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

Mathing attributes in two different documents

Subject: Mathing attributes in two different documents
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 27 Jul 2004 07:05:21 +0000
mathing
Hello all,

I am totally stumbled with the problem below. I hope that I have written my problem in a comprehensive way and that someone can help me with it.

With the following reference xml and two different inputs:

Doc.xml:
<A>
 <B q="1" r="" id="1">Text1</B>
 <B r="" id="2">Text2</B>
</A>

Input documents:
<Input> <!-- Input 1 -->
 <I q="4" r="1" id="1">Something</I>
</Input>

<Input> <!-- Input 2 -->
 <I q="4" id="2">Some other thing</I>
</Input>

I want the attributes that are in the 'I' node of the input document to be written in the output under the following conditions:
1) It must not be the id attribute
2) The attribute must be in the corresponding 'B' node in Doc.xml (The 'B' node with the same id as the 'I' node of the input document).


Given the global variable
<xsl:variable name="Doc" select="document('Doc.xml')/A"/>
I have tried the following two templates:

<!-- First try -->
<xsl:template name="Test">
 <xsl:param name="In"/> <!-- Holds 'I' node -->
 <xsl:variable name="Attributes" select="$Doc/@*[not(name()='id')]"/>
 </xsl:variable>

<Output>
<xsl:for-each select="$In/@*[not(name()='id')][name()=name($Attributes)">
<xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
Some output - <xsl:value-of select="$In"/>
</Output>
</xsl:template>
<!-- Gets only the first attribute in the B node with a given id in Doc.xml -->


On the two inputs it gives the following outputs:
<Output q="4">Some output - Something</Output> <!-- Input 1 -->
<Output>Some output - Some other thing</Output> <!-- Input 2 -->

The second is ok, but the first only gives the first attribute in Doc.xml - it should be:
<Output q="4" r="1">Some output - Something</Output> <!-- Input 1 -->
If I change the order of q and r attributes in Doc.xml, I get r instead of q in my output.


I then tried the following template:
<!-- Second try -->
<xsl:template name="Test">
 <xsl:param name="In"/> <!-- Holds 'I' node -->
 <xsl:variable name="Attributes">
   <xsl:for-each select="$Doc/@*[not(name()='id')]">
     <Attr><xsl:value-of select="name(.)"/></Attr>
   </xsl:for-each>
 </xsl:variable>

<Output>
<xsl:for-each select="$In/@*[not(name()='id')][name()=$Attributes/Attr]">
<xsl:attribute name="{name(.)}"><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
Some output - <xsl:value-of select="$In"/>
</Output>
</xsl:template>
<!-- Second try does not give any output at all -->


But it does not give any output at all (meaning that there is some error in it, but I don't know what).
I don't know if this has anything to do with nodeset versus RTF in variables. As the variable is generated dynamically, I cannot use David Carlisle's method of making a nodeset (select="document('')/xsl:stylesheet/xsl:template/xsl:variable[name='Attribute'])


How can I resolve my problem, preferably in a non-expensive way?

If any use: I am using Microsoft .NET 1.1 - don't know which version of MSXML, if any, that is.

Thank you,
Ragulf Pickaxe :-|

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus


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.