Search code examples
xmlxsltditadita-ot

How to fetch the pubtitle in the ditamap using xsl expressions


For fetching the pubtitle value in the below ditamap using the xsl expressions MY Input XML Dita map file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pubmap
  PUBLIC "urn:pubid:com.sam.doctypes:dita:pubmap" "pubmap.dtd">
<pubmap xml:lang="en-US">
  <pubtitle>
    <mainpubtitle outputclass="book">Sample Word</mainpubtitle>
  </pubtitle>
  <topicref href="topics/topic_1.dita">
    <topicmeta>
      <navtitle>Ram-Files-Raj (RFR)</navtitle>
      <metadata/>
    </topicmeta>
  </topicref>
  <topicref href="topics/topic_2.dita">
    <topicmeta>
      <navtitle>Files-Sampletitle (FST)</navtitle>
      <metadata/>
    </topicmeta>
  </topicref>
</pubmap>

My topic_1.dita file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "urn:pubid:com.sam.doctypes:dita:topic" "topic.dtd">
<topic id="topic_1" xml:lang="en-US" outputclass="Ram-Files-RajRFR"><title>Ram-Files-Raj (RFR)</title></topic>

My topic_2.dita file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "urn:pubid:com.sam.doctypes:dita:topic" "topic.dtd">
<topic id="topic_2" xml:lang="en-US" outputclass="Files-SampletitleFST"><title>Files-Sampletitle (FST)</title></topic>

for topic title fetching i am using the xsl variable as below:

<xsl:variable name="maintitle"><xsl:apply-templates select="/*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]" mode="text-only"/></xsl:variable>

As like above format i want to fetch the diamap main title of this element mainpubtitle outputclass="book" value.

Please suggest me.


Solution

  • Maybe this helps you:

    <xsl:variable name="maintitle">
      <xsl:apply-templates select="//*[contains(@outputclass, 'book')]"/>
    </xsl:variable>
    

    Or if you don't want to use that, maybe this is okay for you:

    <xsl:variable name="maintitle">
       <xsl:value-of select="//mainpubtitle[@outputclass = 'book']/text()"/>
    </xsl:variable>