xml - xmlns is not allowing the xslt to update a value -
so our data has xmlns=
in child/parent stopping child's value being updated xslt
sample data (please note intentionally removed xmlns="http://example.com/abc-artifact"
second record, after <letter
illustrate causing error):
<documents> <document xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <personaldata> <name>jack</name> </personaldata> <documentxml> <letter xmlns="http://example.com/abc-artifact" xsi:schemalocation="http://example.com/abc-artifact.xsd" xsi:type="lettertype"> <headerrecord> <dateofbirth>1971-11-07</dateofbirth> </headerrecord> </letter> </documentxml> </document> <document xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <personaldata> <name>tonja</name> </personaldata> <documentxml> <letter xsi:schemalocation="http://example.com/abc-artifact.xsd" xsi:type="lettertype"> <headerrecord> <dateofbirth>1974-22-10</dateofbirth> </headerrecord> </letter> </documentxml> </document> </documents>
xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="node()"> <xsl:copy> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match="dateofbirth"> <xsl:copy> <xsl:text>newdob</xsl:text> </xsl:copy> </xsl:template> </xsl:stylesheet>
output
<documents> <document xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <personaldata> <name>jack</name> </personaldata> <documentxml> <letter xmlns="http://example.com/abc-artifact"> <headerrecord> <dateofbirth>1971-11-07</dateofbirth> </headerrecord> </letter> </documentxml> </document> <document xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <personaldata> <name>tonja</name> </personaldata> <documentxml> <letter> <headerrecord> <dateofbirth>newdob</dateofbirth> </headerrecord> </letter> </documentxml> </document> </documents>
so can see <dateofbirth>
updated second record, not first. our team not control data , cannot ask them remove xmlns="http://example.com/abc-artifact"
. suggestions? thanks
your template:
<xsl:template match="dateofbirth">
does not match dateofbirth
elements in namespace. this, must use fully-qualified name of element. first, declare namespace , bind prefix, use prefix when addressing element:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:abc="http://example.com/abc-artifact" > <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="node()"> <xsl:copy> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match="abc:dateofbirth"> <xsl:copy> <xsl:text>newdob</xsl:text> </xsl:copy> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment