[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: can you select name() of attributes?
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.
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"/>
<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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|