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

Re: can you select name() of attributes?

Subject: Re: can you select name() of attributes?
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 27 Jul 2004 11:01:16 +0000
select name
Hi again David (and others),

The input and some of my problem should be in my earlier post "Matching attributes in two documents", but I have tried rewriting it a little to match this particular problem.

If some or all of this is not understandable, please tell me, and I will try to elaborate.


Doc1.xml <Input> <I q="input value" s="Invalid attribute">Input</I> </Input>

Doc2.xml
<A>
 <B q="default" r="default">Text1</B>
</A>

Desired output:
<Output q="input value" r="default">Some text in the output element</Output>

Output that I get:
<Output q="default" r="default">Some text in the output element</Output>

If the attribute exists in both Doc1 and Doc2, then I want the value of Doc1 (input value). If it exists only in Doc1, then it should be ignored (invalid attribute), and if only in Doc2, then I want the value of Doc2 (default)

XSL snippets (for the non-desired output):
<!-- Global variables -->
<xsl:variable name="Doc1" select="document('Doc1.xml')/Input/I"/>
<xsl:variable name="Doc2" select="document('Doc2.xml')/A/B"/>


<!-- Template for processing --> <xsl:template name="MakeOutput"> <xsl:variable name="Attr1" select="$Doc1/@*"/> <xsl:variable name="Attr2" select="$Doc2/@*"/>

<Output>
<xsl:for-each select="$Attr2">
<xsl:variable name="Attr" select="."/>
<xsl:if test="not($Attr1)">
<xsl:attribute name="{name($Attr)}"><xsl:value-of select="$Attr"/></xsl:attribute>
</xsl:if>
<xsl:for-each select="$Attr1[name()=name($Attr)]">
<xsl:choose>
<xsl:when test="name()=name($Attr)">
<xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{name($Attr)}"><xsl:value-of select="$Attr"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
Some text in the output element
</Output>
</xsl:template>


Regards,
Ragulf Pickaxe :-)

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail


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.