Groups | Blog | Home
all groups > dotnet xml > january 2005 >

dotnet xml : How to convert attributes to element


Bruce Wood
1/20/2005 9:54:23 AM
You want to use XSLT
(http://www.zvon.org/xxl/XSLTutorial/Output/contents.html) which, if
you don't already know it, will take you a while to learn.

Then, to combine two XML documents into one, you have to choose one as
the primary document (probably your Document1), and use the other
document as a kind of reference lookup. You can do this using the XSLT
document() function, something like this:

<xsl:variable name="elementName" select="name()" />
<xsl:for-each select="@*">
<xsl:variable name="attributeName" select="name()" />
<xsl:variable name="attributeDescription"
select="document(Document2.xml)/elements/element[@name=$elementName]/attribute[@name=$attributeName]/@description"
/>
.... write output XML here...
</xsl:for-each>

A *HUGE* caveat: this is _not_ working XSLT code. I have not tested it.
It is just an idea of where to start. You cannot just plug it into an
XSLT document without understanding XSLT, and trust that the transform
will work. It won't. In particular, I've never tried XPath expressions
with double [] selection in them, so I don't even know if that works or
if I have the syntax right. The point is that there's a way, if you
understand XSLT, to monkey around with this and get it to work.
Tod Johnson
1/20/2005 10:12:52 AM
Hello all,

Can't figure it out. :( Assume that we have 2 XML document:

Document1 (source):

<elements>
<elementA attribute1="value1" attribute2="value2" ... />
<elementA attribute1="value1" attribute2="value2" ... />
...
</elements>

Document2 (element description):

<elements>
<element name="elementA">
<attributes>
<attribute name="attribute1" description="Attribute1 desc" />
<attribute name="attribute2" description="Attribute2 desc" />
</attributes>
</element>
</elements>

Result document must have the following structure:

<elements>
<element name="elementA">
<attributes>
<attribute name="attribute1" description="Attribute1 desc"
value="value1" />
<attribute name="attribute2" description="Attribute2 desc"
value="value2" />
</attributes>
</element>
<element name="elementA">
<attributes>
<attribute name="attribute1" description="Attribute1 desc"
value="value1" />
<attribute name="attribute2" description="Attribute2 desc"
value="value2" />
</attributes>
</element>
</elements>

Please somebody help me,
Tod
AddThis Social Bookmark Button