[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Aron,
Thanks.
Of course the solution I posted doesn't work either, due to limitations of XPath 1.0 and the fact that current() refers not to any node being predicated, but to the current node (the node matched).
Quite an interesting problem, actually. It should be pretty straightforward in XPath 2.0, but the only XSLT 1.0 solutions I've thought of are very ugly and un-XSLTish. That may be unavoidable, again due to limitations in XPath 1.0 -- but before posting one of those I thought I'd give time to see if others can work it out more elegantly....
Anyone?
Oh heck, here's an ugly solution:
It uses a template to fake a function, which returns a null value (which fails the string() test) if there are no children that have following siblings of the same name.
At 03:35 PM 7/5/2005, you wrote:
RE: [xsl] only display if subnodes occur more than once
Subject: RE: [xsl] only display if subnodes occur more than once From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 05 Jul 2005 16:33:49 -0400 |
Aron,
Thanks.
Of course the solution I posted doesn't work either, due to limitations of XPath 1.0 and the fact that current() refers not to any node being predicated, but to the current node (the node matched).
Quite an interesting problem, actually. It should be pretty straightforward in XPath 2.0, but the only XSLT 1.0 solutions I've thought of are very ugly and un-XSLTish. That may be unavoidable, again due to limitations in XPath 1.0 -- but before posting one of those I thought I'd give time to see if others can work it out more elegantly....
Anyone?
Oh heck, here's an ugly solution:
<xsl:template match="root/*"> <xsl:variable name="include"> <xsl:call-template name="include"/> </xsl:variable> <xsl:if test="string($include)"> <xsl:copy-of select="."/> </xsl:if> </xsl:template>
<xsl:template name="include"> <xsl:for-each select="*"> <xsl:if test="following-sibling::*[name()=name(current())]">X</xsl:if> </xsl:for-each> </xsl:template>
It uses a template to fake a function, which returns a null value (which fails the string() test) if there are no children that have following siblings of the same name.
Cheers, Wendell
At 03:35 PM 7/5/2005, you wrote:
The original problem asked (I think), given:
<root> <sub_a> <elem_1/> <elem_2/> <elem_3/> </sub_a> <sub_b> <elem_1/> <elem_2/> <elem_2/> <elem_2/> <elem_3/> </sub_b> <sub_c> <elem_1/> <elem_2/> <elem_3/> </sub_c> </root>
output:
<root> <sub_b> <elem_2/> <elem_2/> <elem_2/> </sub_b> </root>
Namely, output those sub_* which have more than 1 elem_* children named the same; also output the elem_* children.
--A
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] only display if subnodes , Aron Bock | Thread | Re: [xsl] only display if subnodes , David Carlisle |
[xsl] Re: xsl-list Digest 1 Jul 200, cookie king | Date | [xsl] [ANN] A World Class XML Confe, Scott Abel |
Month |