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

RE: Matching elements with specific multiple parents

Subject: RE: Matching elements with specific multiple parents
From: Tony Nassar <tnassar@xxxxxxxxxxxx>
Date: Fri, 1 Apr 2011 14:47:09 -0700
RE:  Matching elements with specific multiple parents
You could easily generate something like the following. It's hardly elegant,
but then again, it is generated code. I don't know what all you need to
accomplish here. One alternative is a different match expression:
child[not(parent::child)]. Moreover, couldn't you just match the <child>
elements that interest you, then <apply-imports> if you're really just copying
them?


        <xsl:template match="foo/child">
             <xsl:call-template name="process-child" />
        </xsl:template>

       <xsl:template match="bar/child">
          <xsl:call-template name="process-child"/>
      </xsl:template>

      <xsl:template name="process-child">
                <child a="{@a}"/>
                <xsl:apply-templates select="*"/>
        </xsl:template>

________________________________________
From: David Lee [dlee@xxxxxxxxxxx]
Sent: Friday, April 01, 2011 5:38 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Matching elements with specific multiple parents

I'm trying to write a template match expression that matches an element only
if it is a child of (1 or more) parents.
Here's an example with 2 parents.
XML:
<?xml version="1.0"?>
<parent>
        <child a="1">
                <child a="2"/>
        </child>
        <foo>
                <child a="3"/>
        </foo>
        <bar>
                <child a="4"/>
        </bar>
</parent>

XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

        <xsl:template match="text()"/>

        <xsl:template match="child[node-name(..) = ( QName((),'foo') ,
QName((),'bar') )]">
                <child a="{@a}"/>
                <xsl:apply-templates select="*"/>
        </xsl:template>
</xsl:stylesheet>


Result (correct)
<child a="3"/>
<child a="4"/>


-=--------------------------------------------------------------
This seems extremely verbose and inelegant but is the best I've come up
with.
I'd like something like
   match="(foo|bar)/child"

but of course that doesn't work.

Any suggestions on a simpler syntax then what I've come up with ?
Note that this is programmatically generated XSLT so I cant easily
hand-optimize simple cases, it needs to work in the 1-N case in a way that's
reasonably constructible programmatically.
My working example is straightforward to construct but it hurts my eyes.
Maybe its just my eyes that needs work :)

Thanks for any ideas


----------------------------------------
David A. Lee
dlee@xxxxxxxxxxx
http://www.xmlsh.org

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.