xsl-list
[Top] [All Lists]

[xsl] Could not select the text() of both parent & child nodes simultaneously

2010-06-15 09:04:47
Hi All,
 
I am stucked with an XSLT 1.0 XPath issue when trying to reference the content 
of either a parent/child nodes at the same time without much luck. Let's have a 
look at the XML document I am trying to parse:
 <p>
<
<
<strong>World Cup Team:</strong>br clear="none" />a shape="rect" >Brasil</a>(30 
goals)<
<br clear="none" />a shape="rect" >Argentina</a>(25 goals)<
<br clear="none" />a shape="rect" >Germany</a>(22 goals)<
<br clear="none" />a shape="rect" >USA</a>(15 goals)<
.......
</p>br clear="none" /> 
The desire transformation outcome would to produce the following XML document:
<team>Brasil (30 goals)<team>
<team>Argentina (25 goals)<team>
<team>Germany (22 goals)<team>
<team>USA (15 goals)<team>
......
 
The following stylesheets achieve either of the text() but not both:
 
<-- Only get the teams but not goals ----->
<xsl:template match="ns:p[ns:strong='World Cup Team:']"> 
<xsl:for-each select="ns:a/text()[normalize-space() != '']">
<team><xsl:value-of select="normalize-space()"/></team>
</xsl:for-each> 
</xsl:template>
 
< -- Get all teams and goals for all nodes on the same line continuously. 
Similar to printf statement -->
<xsl:template match="ns:p[ns:strong='World Cup Team:']"> 
<xsl:for-each select="ns:a/text()[normalize-space() != '']">
<team><xsl:value-of select="../../normalize-space()"/></team>
</xsl:for-each> 
</xsl:template>
 
< --- Only get the goals but not teams --- >
<xsl:template match="ns:p[ns:strong='World Cup Team:']"> 
<xsl:for-each select="text()[normalize-space() != '']"> 
<team><xsl:value-of select="normalize-space()"/></team> 
</xsl:for-each> 
</xsl:template> 
 
I am using JDOM and Saxon 9.1 to carry out the transformation on Windows XP.
 
Any assistance would be much appreciated.
Thanks in advance,
Jack


      


--~------------------------------------------------------------------
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>
--~--