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

RE: XPatch: ancestor and count

Subject: RE: XPatch: ancestor and count
From: "Ivan Pedruzzi" <ipedruzz@xxxxxxxxxxxx>
Date: Fri, 1 Oct 2004 02:10:09 -0400
xpatch download
Andrey,

I slightly modified the XSLT like that

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="menu">
  <table class="menu" border="1">
    <tr><td><xsl:value-of
select="count(ancestor::*)"/></td><td>&#xA0;</td></tr>
    <xsl:for-each select="descendant::menuitem">
     <tr><td><xsl:for-each select="ancestor::*">/<xsl:value-of
select="concat(local-name(), ' ', @title)"/></xsl:for-each></td><td>
     <xsl:value-of select="@title"/></td></tr>
    </xsl:for-each>
  </table>
</xsl:template>
</xsl:stylesheet>

I got consistent results with XalanJ, Saxon 6, Saxon 8, MSXML,
XslTransform.

0
/menu  					1
/menu  					2
/menu /menuitem 2 			2.1
/menu  					3
/menu /menuitem 3 			3.1
/menu /menuitem 3 			3.2
/menu /menuitem 3 			3.3
/menu /menuitem 3 			3.4
/menu /menuitem 3/menuitem 3.4 	3.4.1
/menu /menuitem 3/menuitem 3.4 	3.4.2
/menu /menuitem 3 			3.5
/menu /menuitem 3 			3.6
/menu /menuitem 3/menuitem 3.6 	3.6.1
/menu /menuitem 3/menuitem 3.6 	3.6.2

You may try with LibXSLT to see what path comes out.

Ivan



> -----Original Message-----
> From: Andrey V. Elsukov [mailto:elsukov@xxxxxxxxxxxx]
> Sent: Friday, October 01, 2004 1:18 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XPatch: ancestor and count
>
> Hi,
>
> I have some XML file, for example:
> =======
> <menu>
>       <menuitem title="1"/>
>       <menuitem title="2">
>         <menuitem title="2.1"/>
>       </menuitem>
>       <menuitem title="3">
>         <menuitem title="3.1"/>
>         <menuitem title="3.2"/>
>         <menuitem title="3.3"/>
>         <menuitem title="3.4">
>               <menuitem title="3.4.1"/>
>               <menuitem title="3.4.2"/>
>         </menuitem>
>         <menuitem title="3.5"/>
>         <menuitem title="3.6">
>               <menuitem title="3.6.1"/>
>               <menuitem title="3.6.2"/>
>         </menuitem>
>       </menuitem>
> </menu>
> ======
> and XLS transform:
> ======
> <xsl:template match="menu">
>   <table class="menu">
>     <tr><td><xsl:value-of
select="count(ancestor::*)"/></td><td>&#xA0;</td></tr>
>     <xsl:for-each select="child::menuitem">
>      <tr><td><xsl:value-of select="count(.//ancestor::*)"/></td><td>
>      <xsl:value-of select="@title"/></td></tr>
>     </xsl:for-each>
>   </table>
> </xsl:template>
> ======
> In result the following:
> ======
> 1         - root element
> 2    1    - root, menu
> 3    2    - root, menu, menuitem "2"
> 5    3    - root, menu, menuitem "3", menuitem "3.4" and what???
> ======
> http://www.w3.org/TR/1999/REC-xpath-19991116 :
> * the ancestor axis contains the ancestors of the context node;
> the ancestors of the context node consist of the parent of context
> node and the parent's parent and so on;..
>
> * Function: number count(node-set)
> The count function returns the number of nodes in the argument
node-set.
> ======
> Why the result is 5? It should be equal 4, or not?
>
> PS. I use Perl-5.8.5 + LibXML + LibXSLT..
> --
> Best regards,
> Andrey V. Elsukov

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.