Re: [xsl] can you select name() of attributes?

Subject: Re: [xsl] can you select name() of attributes?
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 27 Jul 2004 10:38:08 +0000
Hi David,

I got somewhat the same solution, but then I run into a different problem, which is why I want to use it as a nodeset. The ones in the input document (let us say $ Doc1) must be in $Doc2, but if they are not in $Doc1, then the (default) value in $Doc2 should be used.


<xsl:variable name="Attr1" select="$Doc1/@*"/>
<xsl:variable name="Attr2" select="$Doc2/@*"/>

<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>


This works if there are no attributes in $Doc1 (if-sentence takes care of that) but if some of the attributes are in $Doc1, then the attributes - by nature of being nested in two for-each loops - will be overwritten (same name), ending in the last iteration creating the output.

Is there something else I can do?

Unfortunately I do not have access to a version which uses XSLT2, and I do not know if MK's solution would work in my case anyway (same problem as above).

Thank you for your time
Ragulf Pickaxe :-)

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail


Current Thread