[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,
Below is the output from your helpful suggestion: ( 1 ) <area> ( 2 ) <interest>Tennis</interest> ( 3 ) <interest>Movie</interest> ( 4 ) <interest>Swimming</interest> ( 5 ) </area>
( a ) <xsl:stylesheet version="1.0" ( g )<area> ( h )<xsl:apply-templates select="//ns:p"/> ( i ) </area> ( j )</xsl:template> ( k )<xsl:template match="ns:p[ns:strong='Nearest Hotels:']"> ( l ) <xsl:for-each select="text()[normalize-space() != '']"> ( m )<nearest_hotels><xsl:value-of select="normalize-space()"/></nearest_hotels> ( n ) </xsl:for-each> ( o ) </xsl:template> ( p )<xsl:template match="ns:p"/> ( q ) ( r )</xsl:stylesheet>
This is the closest thing to what I wanted except that I would it to co-exist with the existing working XSL statements:
( i ) I could not getting another list of element values (e.g. favourite songs...) that comes immediately after the <Interest> element. This may be due to the context node having been changed by when running the aboved stylesheet. ( ii ) There are other element values that I need to retrieve from the same document, where some is made up of a single value while others may have multiple occurrences. I will need to some how include the aboved code segment into the following existing working stylesheet responsible for retrieving other single element values, using the current context node where possible:
<xsl:template match="/"> <area> <xsl:for-each select="/ns:html/ns:body/ns:div[@id='content']/ns:p/ns:strong"> <xsl:if test="contains(.,'Firstname:')"> <xsl:choose> <xsl:when test="contains(.,'Firstname:')"> <firstname><xsl:value-of select="../ns:a"/></firstname> </xsl:when> <xsl:otherwise> <firstname>Unknown</firstname> </xsl:otherwise> </xsl:choose> </xsl:if> <xsl:if test="contains(.,'Surname:')"> <xsl:choose> <xsl:when test="contains(.,'Surname:')"> <surname><xsl:value-of select="../text()"/></surname> </xsl:when> <xsl:otherwise> <surname>Unknown</surname> </xsl:otherwise> </xsl:choose> ......
Thank you so much for the on-going guidances, Jack From: Michael Kay <mike@s...> To: Jack Bush <netbeansfan@y...>; xml-dev@l... Sent: Tuesday, 27 January, 2009 12:54:23 AM Subject: RE: XSLT stylesheet looping through the same node (recursion?) It looks to me as if you would be better off using pattern matching
<xsl:template match="/"> <area> <xsl:apply-templates select="//p"/> </area> </xsl:template> <xsl:template match="ns:p[ns:strong='Interest:']">
<xsl:for-each select="text()[normalize-space() != '']">
<interest><xsl:value-of select="normalize-space()"/></interest>
</xsl:for-each>
</xsl:template>
<xsl:template match="ns:p"/>
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
|