[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

want to add node number to sub node

Subject: want to add node number to sub node
From: Fred Christian <fredc@xxxxxxxxxx>
Date: Thu, 16 Oct 2008 16:03:18 -0700
 want to add node number to sub node
I am using saxon 8 and <xsl:stylesheet version="2.0"

I haven't been using xslt 2.0 features very much and am thinking this is where some would come in handy.
My exact desired result follows - basically I want to add the letter a, b, or c to the Question # depending on if the problem is the 1st, 2nd or 3rd.


Currently in my xsl I have a generic copy template which takes care of just copying all the nodes I care about.
Now I want to modify the text in the <span class="questionHeader"> based on its parent <question>'s position.
I can imagine a slightly cumbersome strategy using xslt 1.0 that involves parameters and writing several more templates to match the various nodes so the param can be passed through correctly. Then using substring functions.
In xslt 2.0 I see regular expressions to change the text, but can't find a faster way to determine the position of the parent node. Pointers anyone? Thanks


<!-- my generic copy template -->
<xsl:template match="*" mode="qcaudio">
   <xsl:copy>
       <xsl:copy-of select="@*"/>
       <xsl:apply-templates mode="qcaudio"/>
   </xsl:copy>
</xsl:template>

### sample xml:
<base>
<group>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 1: </span> ... many nodes...
</question>
</problem>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 1: </span> ... many nodes...
</question>
</problem>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 1: </span> ... many nodes...
</question>
</problem>
</group>
<group>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 2: </span> ... many nodes...
</question>
</problem>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 2: </span> ... many nodes...
</question>
</problem>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 2: </span> ... many nodes...
</question>
</problem>
</group>



### desired result xml:


<group>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 1a: </span> ... many nodes...
</question>
</problem>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 1b: </span> ... many nodes...
</question>
</problem>
<problem ...> ... many nodes ...
<question ...> ... many nodes...
<span class="questionHeader">Question 1c: </span> ... many nodes...
</question>
</problem>
</group>
<group>
... etc....


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.