|
Subject: Re: [xsl] Merging attributes in one XML file with node values in another (identical structure) From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 22 Jun 2006 10:26:54 -0400 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="xpath">
<!-- assuming your input doesn't already have 'xpath' attributes -->
<xsl:for-each select="ancestor-or-self::*">
<xsl:text>/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:if test="count(../*[name()=name(current())]) > 1">
<xsl:text>[</xsl:text>
<xsl:number/>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>I hope that helps, Wendell
O.K. here's my question. It seems like it should be simple but I can't figure it out. I have two XML files. One with data in the node values, and one with data in attributes. They have the same exact structure.
<a> <b> <node>1</node> </b> <c> <d> <node>2</node> </d> </c> </a>
... and ...
<a> <b val="x"> <node width="10"/> </b> <c> <d val="z"> <node height="15"/> </d> </c> </a>
As you can see the word "node" node appears at /a/b/node and a/c/d/node but has two distinct values and attributes. Is there a way to transform the first one with XSLT to produce the following results:
<a> <b val="x"> <node width="10">1</node> </b> <c> <d val="z"> <node height="15">2</node> </d> </c> </a>
...essentially combining the node values of one file with the attributes in the other. I've really been struggling with this. I was able to do it with recursion, but I'm looking for a way to do it without using recursive procedures. I don't think it's possible. Is it?
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Merging attributes in one XML, Minervini, Chris | Thread | Re: [xsl] Merging attributes in one, Wendell Piez |
| [xsl] Merging attributes in one XML, Minervini, Chris | Date | Re: [xsl] Merging attributes in one, Wendell Piez |
| Month |