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

RE: XPath problem with getting all ancestors

Subject: RE: XPath problem with getting all ancestors
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 23 Oct 2009 11:58:40 +0100
RE:  XPath problem with getting all ancestors
My guess (and it's a completely wild one) is that you aren't applying
templates to the note element in the source tree as you have shown it, but
to a copy of the note element in some smaller tree, probably a tree rooted
at the para element.

To confirm that we would need to see more of the stylesheet. Or, within the
match="note" template, do

<xsl:message><xsl:copy-of select="/"/></xsl:message>

to see what tree you are processing at the time.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay  

> -----Original Message-----
> From: Jostein Austvik Jacobsen [mailto:josteinaj@xxxxxxxxx] 
> Sent: 23 October 2009 11:27
> To: xsl-list
> Subject:  XPath problem with getting all ancestors
> 
> I've got a document like this:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <document>
> 	<article>
> 		<meta>
> 			<title>Title</title>
> 		</meta>
> 		<content>
> 			<headline>Headline</headline>
> 			<para>
> 				<note id="1">text</note>
> 			</para>
> 		</content>
> 	</article>
> </document>
> 
> And in a template for the note tags I'm trying to use the 
> ancestor axis to get the list [ para , content , article ].
> However, I only seem to get [ para ] with ancestor::* and [ para , ""
> ] with ancestor::node().
> When I test it like this:
> 
> <xsl:template match="note">
> 		ancestors="<xsl:value-of select="count(ancestor::*)"/>"
> 		preceding="<xsl:value-of select="count(preceding::*)"/>"
> 		contentNum="<xsl:value-of 
> select="count(preceding::content)"/>"
> </xsl:template match>
> 
> ...I get ancestors="1", preceding="2" and contentNum="0" as output.
> 
> What I actually need to do is to count the number of content 
> nodes preceding the current note (relevant for the input XML 
> note numbering scheme). I did so earlier in the document (for 
> referencing the actual
> notes) when matching document like this:
> 
> <xsl:template match="document">
> 	(...)
> 	<xsl:for-each select="//note">
> 		<note>
> 			<xsl:attribute name="id"><xsl:value-of 
> select="count(ancestor::content/preceding::content)"/></xsl:attribute>
> 			<p><xsl:apply-templates/></p>
> 		</note>
> 	</xsl:for-each>
> 	(...)
> </xsl:template>
> 
> So here I get access to all of the notes ancestors. In 
> retrospect I could probably have used 
> select="count(preceding::content)" instead, but still...
> 
> How come that I cannot access the notes ancestors from my 
> note template?
> 
> Regards
> Jostein

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.