Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2016, 12:21 AM
Registered User
 
Join Date: Dec 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Select and compare number node

I would like to target the topicref > topic > topic and change the title with numbering.

I have the following dita map
Code:
<map>
   <chapter>
      <topicref href="ditafile1#topic1">
      <topicref href="ditafile1#topic2">
      <topicref href="ditafile1#topic3">
      and so forth
   </chapter>

   <chapter>
     <topicref href="ditafile2#topic2-1>
     <topicref href="ditafile2#topic2-2>
     and so forth
   </chapter>
</map>
Dita file 1:
Code:
<topic>
  <topic>
      <title>Introduction</title>
  </topic>
  <topic id="topic1>
      <title>Number 1</title>
  </topic>
  <topic id="topic2>
      <title>Number 2</title>
  </topic>
</topic>
Dita file 2
Code:
<topic>
  <topic id="topic2-1">
      <title>Number 2-1</title>
  </topic>
  <topic>
      <title></title>
  </topic>
  <topic id="topic2-2">
      <title>Number 2-2</title>
  </topic>
</topic>
By default,
Code:
<xsl:template match="topic/topic/title">
    <h2>
          <xsl:value-of select="text()"/>
    </h2>
</xsl:template>
If topicref id in href and topic topic id match, change the title, add a numbering 1.1.
Someone suggested this solution, but <xsl:template match="topicref[@href]"> causes some issue that stop all my other html files from generating.

Code:
<xsl:template match="/">
        <xsl:apply-templates select="//topicref"/>
    </xsl:template>

    <xsl:template match="topicref[@href]">
        <xsl:variable name="href" as="xs:string" select="string(@href)"/>
        <xsl:variable name="topicFile" as="xs:string" select="substring-before($href,'#')"/>
        <xsl:variable name="id" as="xs:string" select="substring-after($href,'#')"/>
        <xsl:variable name="levelStr" as="xs:string">
            <xsl:number level="multiple" count="chapter|topicref" format="1.1"/>
        </xsl:variable>
        <xsl:variable name="title" as="text()*">
            <xsl:apply-templates select="document(concat(string(resolve-uri('.', static-base-uri())),$topicFile))//topic[string(@id) eq $id]/title"/>
        </xsl:variable>
        <xsl:value-of select="$levelStr"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="$title"/>
        <xsl:text>&#x0A;</xsl:text>
    </xsl:template>
Expected output (for the title):
<h2'>1.1 Number 1</h2> // ignore the ' <br/>
<h2'>1.2 Number 2</h2> // ignore the ' <br/>
<h2'>2.1 Number 2-1</h2> // ignore the ' <br/>
<h2'>2.2 Number 2-2</h2> // ignore the ' <br/>

Questions:
How to target for each topicref , the topic topic title change it add numbering infront.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Compare value of an xml node with a String using xsl : if azhus XSLT 1 May 2nd, 2014 05:40 AM
Compare current value with previous parent node ratjetoes XSLT 2 July 17th, 2008 06:15 AM
XSLT Help to get value from Upper Node by compare pixelheart XSLT 10 May 1st, 2008 12:25 PM
Compare select box Dj Kat Javascript How-To 4 November 15th, 2007 11:03 AM
compare the values in a select box ayse1st BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 January 7th, 2006 03:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.