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

RE: only display if subnodes occur more than once

Subject: RE: only display if subnodes occur more than once
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 05 Jul 2005 16:33:49 -0400
xpath all subnodes
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

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