Subject: Re: [xsl] Could not select the text() of both parent & child nodes simultaneously From: Jack Bush <netbeansfan@xxxxxxxxxxxx> Date: Wed, 16 Jun 2010 01:30:28 -0700 (PDT) |
Hi David, I am very new to XML development, not to mention about XSLT and hesitates to move to version 2.0 for 3 reasons: ( i ) 1.0 is sufficient for what I need to do but there is bound to be better ways to do it in 2.0. ( ii ) XPath & XSLT 2.0 comes at a cost for recent release of Saxon licensing models. ( iii ) Believes that a schema/DTD is required by the stylesheet. Not familiar with how to set it up yet. Any how, below is the error I have encountered after having changed the stylesheet version to 2.0 (line 2): <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="ns"> ..... Error on line 83 XPTY0004: Cannot compare java-type:definition.Sport to xs:string at xsl:apply-templates (#13) processing //p[1] ; SystemID: ; Line#: 83; Column#: -1 net.sf.saxon.trans.XPathException: Cannot compare java-type:definition.Sport to xs:string at net.sf.saxon.expr.ValueComparison.compare(ValueComparison.java:638) at net.sf.saxon.expr.GeneralComparison.compare(GeneralComparison.java:619) at net.sf.saxon.expr.SingletonComparison.effectiveBooleanValue(SingletonComparis on.java:102) at net.sf.saxon.expr.QuantifiedExpression.effectiveBooleanValue(QuantifiedExpres sion.java:226) at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:679) at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:203) at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:345) at net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:210) at net.sf.saxon.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:1 74) at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:556) at net.sf.saxon.instruct.Instruction.process(Instruction.java:93) at net.sf.saxon.expr.LetExpression.process(LetExpression.java:378) at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:2 96) at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:203) at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:345) at net.sf.saxon.Controller.transformDocument(Controller.java:1807) at net.sf.saxon.Controller.transform(Controller.java:1621) Back to the original question, what is the XPath statement in XSLT to get the content of both <a> (team) and <p> (goals) at the sametime? Below are some more examples I have attempted without success still: ( i ) <xsl:template match="ns:p[ns:strong='World Cup Team:']"> <xsl:for-each select="ns:a/text()[normalize-space() != '']"> <team><xsl:value-of select="concat( or../ns:a/normalize-space(), normalize-space())"/></team> </xsl:for-each> </xsl:template> Output <team>Brasil (30 goals)<team> <team>Brasil (25 goals)<team> <team>Brasil (22 goals)<team> <team>Brasil (15 goals)<team> ( iii ) <xsl:template match="ns:p[ns:strong='World Cup Team:']"> <xsl:for-each select="ns:a/text()[normalize-space() != '']"> <team><xsl:value-of select="concat(ns:a/text()[normalize-space()], text()[normalize-space()])"/></team> </xsl:for-each> </xsl:template> or ( iv ) <xsl:template match="ns:p[ns:strong='World Cup Team:']"> <xsl:for-each select="ns:a/text()[normalize-space() != '']"> <team><xsl:copy-of select="concat(ns:a/text()[normalize-space()], text()[normalize-space()])"/></team> </xsl:for-each> </xsl:template> Output<team> /> <team> /> <team> /> <team> /> Attempts ( i ) or ( ii ) appears to be closest but the context of <a> (e.g. Brasil) needs to move to the next node (e.g. <team> Argentina (25 goals) <team>) and so on. I am more than happy to accept suggestions on how best to retrieve these data with either version. Many thanks again, Jack ( ii ) <xsl:template match="ns:p[ns:strong='World Cup Team:']"> <xsl:for-each select="ns:a/text()[normalize-space() != '']"> <team><xsl:copy-of select="concat(../ns:a/normalize-space(), normalize-space())"/></team> </xsl:for-each> </xsl:template> ----- Original Message ---- From: David Carlisle <davidc@xxxxxxxxx> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Sent: Wed, 16 June, 2010 12:10:32 AM Subject: Re: [xsl] Could not select the text() of both parent & child nodes simultaneously 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. > <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. > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Could not select the text, David Carlisle | Thread | Re: [xsl] Could not select the text, David Carlisle |
Re: [xsl] group-starting-with drops, Imsieke, Gerrit, le- | Date | Re: [xsl] Could not select the text, David Carlisle |
Month |