Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XPath - How to query for
elements ?

From: "George Bina" <george@---------.--->
To: NULL
Date: 5/4/2006 1:13:00 AM

Use
following-sibling::dd[preceding-sibling::dt[1]=current()]
get the following dd element whose first preceding dt is the surrent dt
element.


For instance the folllowing stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output indent="yes"/>
  <xsl:template match="/">
    <result>
      <xsl:apply-templates select="//dt"/>
    </result>
  </xsl:template>

  <xsl:template match="dt">
    <for value="{.}">
      <xsl:for-each

select="following-sibling::dd[preceding-sibling::dt[1]=current()]">
        <got value="{.}"/>
      </xsl:for-each>
    </for>
  </xsl:template>
</xsl:stylesheet>

will give you

<?xml version="1.0" encoding="utf-8"?>
<result>
   <for value="A">
      <got value="a"/>
   </for>
   <for value="B">
      <got value="b1"/>
      <got value="b2"/>
   </for>
   <for value="C"/>
   <for value="D"/>
</result>

Note that the above assumes no namespace for the source elements, if
you use the XHTML namespace then you need to qualify the name tests
with the appropriate prefix, that is instead of dd for instance you
should have xhtml:dd and declare the XHTML namespace mapped to xhtml
prefix.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com



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