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

Subject: Re: [xsl] can you select name() of attributes?
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Tue, 27 Jul 2004 05:16:50 -0600

Take a look at which in a nutshell is a combination of Aspect-Oriented Software Development and XML/XSLT. By taking an instance document and comparing it to a definition document it then looks to a third document to determine if an element or attribute should be woven before, in-place of (around), or after an element or attribute defined in the originating document. Think of it as a kind of "floating" schema that can adapt to any particular situation and define the final output (and whether that final output is valid) accordingly.

Best of luck!


Ragulf Pickaxe wrote:

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>

 <B q="default" r="default">Text1</B>

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/@*"/>

<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:for-each select="$Attr1[name()=name($Attr)]">
<xsl:when test="name()=name($Attr)">
<xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
<xsl:attribute name="{name($Attr)}"><xsl:value-of select="$Attr"/></xsl:attribute>
Some text in the output element

Ragulf Pickaxe :-)

Add photos to your e-mail with MSN 8. Get 2 months FREE*.

Current Thread