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

Re: Could not select the text() of both parent & child

Subject: Re: Could not select the text() of both parent & child nodes simultaneously
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 15 Jun 2010 15:10:32 +0100
Re:  Could not select the text() of both parent & child
On 15/06/2010 15:04, Jack Bush wrote:
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:

The following is not well formed, so hopefully your source doesn't look like that, it's so far from being well formed i would hesitate to guess what your input does like, which makes answering the question a bit hard.
<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>

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

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

I am using JDOM and Saxon 9.1 to carry out the transformation on Windows XP.

If you are using saxon 9, why do you ask for an XSLt 1 solution, since you are using XSLT 2?

________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________

Current Thread


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.
First Name
Last Name
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.