i want to replace the substring of an attribute value with another value. in the sample below, i would like to take all elements with the attribute tagName = "blubb", and replace their tagValue, by finding the string "abc" in it, and replacing it with xyz. Also, the string "def" in the same attribute (if existign) should be replaced with AAA.
Sample Input:
<shop>
<items>
<item id="1">
<tag tagName = "Description" tagValue ="Item 1" />
<tag tagName = "Price" tagValue = "5.00" />
<tag tagName = "Currency" tagValue = "USD" />
<tag tagName = "blubb" tagValue = "abc,def,ghi,jkl" />
</item>
<item id="2">
<tag tagName = "Description" tagValue ="Item 2" />
<tag tagName = "Price" tagValue = "5.00" />
<tag tagName = "Currency" tagValue = "EUR" />
<tag tagName = "blubb" tagValue = "def,ghi,jkl" />
</item>
<item id="2">
<tag tagName = "Description" tagValue ="Item 2" />
<tag tagName = "Price" tagValue = "5.00" />
<tag tagName = "Currency" tagValue = "EUR" />
<tag tagName = "blubb" tagValue = "abc,def,jkl" />
</item>
</items>
</shop>
Expected Output (abc replaced with xyz and def replaced with AAA)
<shop>
<items>
<item id="1">
<tag tagName = "Description" tagValue ="Item 1" />
<tag tagName = "Price" tagValue = "5.00" />
<tag tagName = "Currency" tagValue = "USD" />
<tag tagName = "blubb" tagValue = "xyz,AAA,ghi,jkl" />
</item>
<item id="2">
<tag tagName = "Description" tagValue ="Item 2" />
<tag tagName = "Price" tagValue = "5.00" />
<tag tagName = "Currency" tagValue = "EUR" />
<tag tagName = "blubb" tagValue = "AAA,ghi,jkl" />
</item>
<item id="2">
<tag tagName = "Description" tagValue ="Item 2" />
<tag tagName = "Price" tagValue = "5.00" />
<tag tagName = "Currency" tagValue = "EUR" />
<tag tagName = "blubb" tagValue = "xyz,AAA,jkl" />
</item>
</items>
</shop>
Is that possible with xslt?
Thanks!
UPDATE - i tried adapting my xsl with the replace function- i had a copy-of before and adapted it to a copy as in the sample below, however i dont get any data now anymore, so i tried making it work with copy-of again When i do that, it doesn't replace anything. I suppose that is because i have twiche xsl:template in it, is it?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:template match="items">
<xsl:copy-of select="item[@type='DEVICE']/tag[@tagName='Currency' and starts-with(@tagValue,'EUR')]/.."/>
</xsl:template>
<xsl:template match="item/tag[@tagName='blubb']">
<xsl:param name="tagValue" />
<xsl:variable name="tagValue" select="replace($tagValue,'abc','xyz')"/>
<xsl:variable name="tagValue" select="replace($tagValue,'def','AAA')"/>
</xsl:template>
</xsl:stylesheet>