B
Bilal
Hello all,
I came across this problem while working out the bugs in my identity
trasnformation stylesheets but sidestepped it for later to see if there
is an easier/better solution. This is essentially following up to my
last post so apologies for repeating parts of the post.
The transformation stylesheet is (after corrections from kind
contributors
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/message/Control/Trace/Id">
<xsl:copy>
<!-- use that if you have other attributes to copy -->
<xsl:apply-templates select="@*"/>
<xsl:attribute name="extension">bbb-999</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
which puts/adds a new value to the
"/message/Control/Trace/Id/@extension" attribute and the xml to be
transformed is:
<?xml xmlns="someNS" version="1.0" encoding="ISO-8859-1"?>
<message>
<id>Text</id>
<creationTime>Text</creationTime>
<versionCode/>
<Id>Text</Id>
<processingCode/>
<processingModeCode/>
<acceptCode/>
<commRcv>
<device>
<id extension="Old_Ext">Text</id>
</device>
</commRcv>
<commSnd>
<device>
<id>Text</id>
</device>
</commSnd>
<Control>
<author>
<Entity>
<id>Text</id>
<code/>
<Organization>
<id>Text</id>
</Organization>
</Entity>
</author>
<Trace>
<Id extension="OLD">Text</Id>
<person>
<value/>
<Text>String</Text>
</person>
<birthTime>
<value>Text</value>
<Text>String</Text>
</birthTime>
<name>
<value>Text</value>
<Text>String</Text>
</name>
</Trace>
</Control>
</message>
The issue is that the 'data' XML actually defines a default namespace,
as I have now indicated, which I had removed to ease troubleshooting the
stylesheet (and in my previous postings). The stylesheet obviously works
if e.g. by declaring xmlns:dns="someNS" and using the xpath
"/dns:message/dns:Control/dns:Trace/dns:Id/@extension" instead. However
this approach is cumbersome because I have to then mess with the
original "plain" xpath by adding in the prefix etc. and rather avoid
that if I can.
So is there some other way to add the attribute during transformation
WITHOUT using the namespace-qualified Xpath? A trivial solution would be
to remove the default NS declaration from the data XML before
processing, transform it, and then add the default NS during a
subsequent transformation. From what I understand of the specs, I
believe the last 'step' is a NO NO and the transformation engine is
supposed to either not perform the action or return an error.
Is there a better way to do this then? Just for curiosity, why is the
modified Xpath required for the transformation whereas apps like XMLSpy
do evaluate the "plain" Xpath fine?
Regards,
Bilal B.
I came across this problem while working out the bugs in my identity
trasnformation stylesheets but sidestepped it for later to see if there
is an easier/better solution. This is essentially following up to my
last post so apologies for repeating parts of the post.
The transformation stylesheet is (after corrections from kind
contributors
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/message/Control/Trace/Id">
<xsl:copy>
<!-- use that if you have other attributes to copy -->
<xsl:apply-templates select="@*"/>
<xsl:attribute name="extension">bbb-999</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
which puts/adds a new value to the
"/message/Control/Trace/Id/@extension" attribute and the xml to be
transformed is:
<?xml xmlns="someNS" version="1.0" encoding="ISO-8859-1"?>
<message>
<id>Text</id>
<creationTime>Text</creationTime>
<versionCode/>
<Id>Text</Id>
<processingCode/>
<processingModeCode/>
<acceptCode/>
<commRcv>
<device>
<id extension="Old_Ext">Text</id>
</device>
</commRcv>
<commSnd>
<device>
<id>Text</id>
</device>
</commSnd>
<Control>
<author>
<Entity>
<id>Text</id>
<code/>
<Organization>
<id>Text</id>
</Organization>
</Entity>
</author>
<Trace>
<Id extension="OLD">Text</Id>
<person>
<value/>
<Text>String</Text>
</person>
<birthTime>
<value>Text</value>
<Text>String</Text>
</birthTime>
<name>
<value>Text</value>
<Text>String</Text>
</name>
</Trace>
</Control>
</message>
The issue is that the 'data' XML actually defines a default namespace,
as I have now indicated, which I had removed to ease troubleshooting the
stylesheet (and in my previous postings). The stylesheet obviously works
if e.g. by declaring xmlns:dns="someNS" and using the xpath
"/dns:message/dns:Control/dns:Trace/dns:Id/@extension" instead. However
this approach is cumbersome because I have to then mess with the
original "plain" xpath by adding in the prefix etc. and rather avoid
that if I can.
So is there some other way to add the attribute during transformation
WITHOUT using the namespace-qualified Xpath? A trivial solution would be
to remove the default NS declaration from the data XML before
processing, transform it, and then add the default NS during a
subsequent transformation. From what I understand of the specs, I
believe the last 'step' is a NO NO and the transformation engine is
supposed to either not perform the action or return an error.
Is there a better way to do this then? Just for curiosity, why is the
modified Xpath required for the transformation whereas apps like XMLSpy
do evaluate the "plain" Xpath fine?
Regards,
Bilal B.