[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT stylesheet looping through the same node (recursion?)
Hi Michael,
We are finally seeing the light at the end of this tunnel. I managed to extract every element values in <p> (single/multiples) except one with the following structure:
<p> <strong>Hobbies:</strong> <a shape="rect" href="http://www.hobbies.com/fishing" title="Shark Hunting">Coral Bay</a> fishing </p>
I tried the following combinations to get the value 'fishing' without much luck:
<xsl:template match="ns:p[ns:strong='Hobbies:']"> <xsl:for-each select="text()[normalize-space() != '']"> <hobbies><xsl:value-of select="normalize-space()"/></hobbies> </xsl:for-each> </xsl:template>
or
<xsl:template match="ns:p[ns:strong='Hobbies:']"> <xsl:for-each select="../ns:a/text()[normalize-space() != '']"> <hobbies><xsl:value-of select="normalize-space()"/></hobbies> </xsl:for-each> </xsl:template>
Yet an earlier approach such as the one below did picked up the value 'fishing':
<xsl:template match="/"> <employee> <xsl:for-each select="/ns:html/ns:body/ns:div[@id='content']/ns:p/ns:strong"> <xsl:choose> <xsl:when test="contains(.,'Hobbies:')"> <hobbies><xsl:value-of select="../ns:a"/></hobbies> </xsl:when> <xsl:otherwise> <hobbies>None</hobbies> </xsl:otherwise> </xsl:choose> </xsl:for-each>> </employee> </xsl:template>
Naturally, I would like to use the pattern matching approach (later) to complete the extraction of all element values in the same document.
Again, your invaluable suggestion is much appreciated. Jack From: Michael Kay <mike@s...> To: Jack Bush <netbeansfan@y...>; xml-dev@l... Sent: Wednesday, 28 January, 2009 12:13:03 AM Subject: RE: XSLT stylesheet looping through the same node (recursion?) Having got this template rule working, you can now simply add additional rules, for example
<xsl:template match="ns:p[ns:strong='Nearest Hotels:']">
<xsl:for-each select="text()[normalize-space() != '']">
<nearestHotels><xsl:value-of select="normalize-space()"/></nearestHotels>
</xsl:for-each>
</xsl:template>
That's the beauty of doing it through template rules rather than big xsl:choose statements - it makes your code very easy to modify and extend.
Michael Kay
http://www.saxonica.com/
Stay connected to the people that matter most with a smarter inbox. http://au.rd.yahoo.com/galaxy/mail/tagline2/*http://au.docs.yahoo.com/mail/smarterinbox.
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|