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

Position() on template matches

Subject: Position() on template matches
From: "Kevin L. Cobb" <kevin.cobb@xxxxxxxxxxxx>
Date: Tue, 25 Oct 2005 16:15:38 -0400
this matche
I have an element in an XML document whose node I need the position of
in the context of my template match (unsure if I'm forming the question
correctly, sorry). The Source XML and the StyleSheet are below. The
resulting output is:

<?xml version="1.0" encoding="UTF-8"?>
<out>
  <myOut>1</myOut>
  <myOut>1</myOut>
  <myOut>1</myOut>
  <myOut>1</myOut>
</out>

But I the output to be:
<?xml version="1.0" encoding="UTF-8"?>
<out>
  <myOut>1</myOut>
  <myOut>2</myOut>
  <myOut>3</myOut>
  <myOut>4</myOut>
</out>

I suppose this is by design because all of the "output" nodes exist
separately in the XML file, i.e. if all of the "tester" elements were
under a single "output" node, I'd be OK. Would this be considered poorly
designed XML? Not that it matters because I don't control the XML in
this case.

Thanks for any and all help.

-Kevin


<!-- ============== -->
<!-- The Source XML -->
<!-- ============== -->
<test>
   <output>
      <tester>One</tester>
   </output>
   <output>
      <tester>Two</tester>
   </output>
   <output>
      <tester>Three</tester>
   </output>
   <output>
      <tester>Four</tester>
   </output>
</test>

<!-- ============== -->
<!-- The StyleSheet -->
<!-- ============== -->
<?xml version="1.0"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:template match="/">
      <out>
         <xsl:apply-templates/>
      </out>
   </xsl:template>

   <xsl:template match="output/tester">
      <xsl:variable name="pos"><xsl:number/></xsl:variable>
      <xsl:element name="myOut"><xsl:value-of
select="$pos"/></xsl:element>
   </xsl:template>
</xsl:stylesheet>

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.