P
patrizio.trinchini
Hi All,
I'would like to write an XSL transformation that changes the value of
the atribute of a given element according to the value of another
atttribute of the same element.
For instance, given the following XML file:
<?xml version="1.0" encoding="UTF-8"?>
<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNameSpaceSchemaLocation="sample.xsd">
<parent-element>
<child-element name="AAA" value="XXX"/>
<child-element name="BBB" value="XXX"/>
</parent-element>
</sample>
I would obtain the following one:
<?xml version="1.0" encoding="UTF-8"?>
<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNameSpaceSchemaLocation="sample.xsd">
<parent-element>
<child-element name="AAA" value="AAA_VALUE"/>
<child-element name="BBB" value="BBB_VALUE"/>
</parent-element>
</sample>
where the value of the 'value' attribute of the first child-element has
been changed to AAA_VALUE because the value of the 'name' attribute was
AAA; the value of the 'value' attribute of the second child-element has
been changed to BBB_VALUE because the value of the 'name' attribute was
AAA.
I wrote the following XSLT to do the job:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="child-element[@name='AAA']">
<xsl:apply-templates select="@*[local-name() != 'value']" />
<xsl:attribute name="value">
<xsl:text>AAA_VALUE</xsl:text>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
but it only handles the first child-element; I don't know how to handle
both the child-element, and possibly more then two, in a single
transform, is it possible? or maybe I need to chain multiple
transformations?
Thanks a lot for your help
Patrizio
I'would like to write an XSL transformation that changes the value of
the atribute of a given element according to the value of another
atttribute of the same element.
For instance, given the following XML file:
<?xml version="1.0" encoding="UTF-8"?>
<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNameSpaceSchemaLocation="sample.xsd">
<parent-element>
<child-element name="AAA" value="XXX"/>
<child-element name="BBB" value="XXX"/>
</parent-element>
</sample>
I would obtain the following one:
<?xml version="1.0" encoding="UTF-8"?>
<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNameSpaceSchemaLocation="sample.xsd">
<parent-element>
<child-element name="AAA" value="AAA_VALUE"/>
<child-element name="BBB" value="BBB_VALUE"/>
</parent-element>
</sample>
where the value of the 'value' attribute of the first child-element has
been changed to AAA_VALUE because the value of the 'name' attribute was
AAA; the value of the 'value' attribute of the second child-element has
been changed to BBB_VALUE because the value of the 'name' attribute was
AAA.
I wrote the following XSLT to do the job:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="child-element[@name='AAA']">
<xsl:apply-templates select="@*[local-name() != 'value']" />
<xsl:attribute name="value">
<xsl:text>AAA_VALUE</xsl:text>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
but it only handles the first child-element; I don't know how to handle
both the child-element, and possibly more then two, in a single
transform, is it possible? or maybe I need to chain multiple
transformations?
Thanks a lot for your help
Patrizio