Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


XPath Node Reference Question

From: andy.dreistadt@-----.---
To: NULL
Date: 3/1/2006 8:57:00 AM
Hi all,

I am having a bit of trouble identifying the first element of a set of
children.  I had an answer that worked for a while until the case where
there was an element that was identical to the first element.  Here is
what I had before:


XML Document
==================
<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<A>
<B>Some Paragraph 1</B>
<B>Some Paragraph 2</B>
<B>Some Paragraph 3</B>
<B>Some Paragraph 1</B>
<B>Some Paragraph 5</B>
</A>
</ROOT>

XSL Transform
==================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
  <xsl:template match="B">
    <xsl:choose>
      <xsl:when test="../B[1]=.">
        <xsl:text>first B</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>next B</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>


The output for this now is:
first B
next B
next B
first B
next B

I realize that the test in the xsl above is comparing the value of the
element and whenever the value of the current node is equal to the
value of B[1] the test passes and outputs "first B". In reality
however, I need to only identify the actual first child and would like
the output to look like:

first B
next B
next B
next B
next B

Any thoughts?

Thanks in advance,
Andy



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent