C
Caroline M
Hi there,
I am developing an XML-based messaging application that has to support
several versions of the message specification. The way I am doing that
is by using XSLT to transform messages from one version into another.
Here's a dummy example that I am using for my unit tests:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/mos">
<xsl:copy>
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
<version_2.8>2.8.1</version_2.8>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This just adds a new element with version information after the others.
This works fine. The trouble comes when I want one of these that only
works on a specific type of message and I wanted to embed the name of
the message into the XSL file. I read up on embedding XML inside XSL
files and read that you could do it by putting the XSL into a separate
namespace. So here is an example of how I am doing that:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mos="http://example.com/mos_data">
<mos:message_type>listMachInfo</mos:message_type>
<xsl:template match="/mos">
<xsl:copy>
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
<version_3.0>3.1</version_3.0>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
To load these files we use a library that was developed internally as a
wrapper around libxml. Its possible I'm using the library incorrectly
but I want to eliminate bad syntax first. I can parse the above files
successfully as both an ordinary XML document, and as an XSL document.
But what I am trying to do is get hold of the data in the
mos:message_type element. We have a function called
"locate_single_node" which takes an XPath expression and a list of
namespaces:
Here's the expression I use:
pxmlNode = pxmlDoc->locate_single_node("/mos:message_type", ns);
where ns is a list of namespaces in the document. However, the node is
not found. Any ideas?
Many thanks,
Caroline M
I am developing an XML-based messaging application that has to support
several versions of the message specification. The way I am doing that
is by using XSLT to transform messages from one version into another.
Here's a dummy example that I am using for my unit tests:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/mos">
<xsl:copy>
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
<version_2.8>2.8.1</version_2.8>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This just adds a new element with version information after the others.
This works fine. The trouble comes when I want one of these that only
works on a specific type of message and I wanted to embed the name of
the message into the XSL file. I read up on embedding XML inside XSL
files and read that you could do it by putting the XSL into a separate
namespace. So here is an example of how I am doing that:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mos="http://example.com/mos_data">
<mos:message_type>listMachInfo</mos:message_type>
<xsl:template match="/mos">
<xsl:copy>
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
<version_3.0>3.1</version_3.0>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
To load these files we use a library that was developed internally as a
wrapper around libxml. Its possible I'm using the library incorrectly
but I want to eliminate bad syntax first. I can parse the above files
successfully as both an ordinary XML document, and as an XSL document.
But what I am trying to do is get hold of the data in the
mos:message_type element. We have a function called
"locate_single_node" which takes an XPath expression and a list of
namespaces:
Here's the expression I use:
pxmlNode = pxmlDoc->locate_single_node("/mos:message_type", ns);
where ns is a list of namespaces in the document. However, the node is
not found. Any ideas?
Many thanks,
Caroline M