Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using XML and XSL together

Reply
Thread Tools

Using XML and XSL together

 
 
Caroline M
Guest
Posts: n/a
 
      01-18-2007
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"
xmlnssl="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"
xmlnssl="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

 
Reply With Quote
 
 
 
 
Caroline M
Guest
Posts: n/a
 
      01-18-2007
> <xsl:stylesheet version="1.0"
> xmlnssl="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>


Responding to my own post... you may have noticed the lack of
indentation with the above file. This is because of the way it is
generated programatically by my test code. One of the consequences is
that it is difficult to see the hierarchy when looking at it and I
fotgot that the mos:message_type node was inside the xsl:stylesheet
node. Once I fixed that the code worked

Caroline M.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML to XML Filtering using XSL Problem generalr XML 0 04-20-2010 07:58 PM
XML to XML using XSL. Please, help me! Thank You! shapper ASP .Net 2 11-19-2006 03:22 AM
XML to XML using XSL @do XML 3 09-27-2006 02:57 PM
xsl:sort using an xsl:variable as the sort key jobooker@gmail.com XML 2 09-05-2006 03:51 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM



Advertisments