xsl-list
[Top] [All Lists]

Re: can you select name() of attributes?

2004-07-27 04:16:50
Ragulf,

Take a look at http://www.aspectxml.org 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!

<M:D/>

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>

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


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--