xsl-list
[Top] [All Lists]

Re: Same XPath expression with diferent results

2004-12-07 14:35:34
I don't understand this. Giving the xml in
http://gti.clientes.gtinformatica.pt/Site/Java/Menus.xml if
i inspect the xpath expression //menu (using the jEdit XPath
Tool) it gives a count 0f 8. That's what i expected.

But in

               <xsl:template match="//menu">
           blabla
               </xsl:template>

blabla only appears 3 times, corresponding to the /menus/menu.
Why this isn't giving the same 8 results?

Because the menu elements are nested, and your template does not continue 
the recursive processing of the source tree, you never reach the menu 
elements that are descendants of another menu element.

You don't show a full stylesheet, so I'm just guessing, but try these two 
stylesheets produce the same output, and contrast the typical "push" vs. 
"pull" styles:

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

<xsl:template match="node() | attribte::*"/>

<xsl:template match="menu">
  <xsl:text>blabla</xsl:text>
  <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

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

<xsl:template match="/">
  <xsl:for-each select="//menu">
    <xsl:text>blabla</xsl:text>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Note that "//" is not necessary in a match pattern.

Dave

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--