Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Namespace Nodes... not a really an attribute? Namespace Nodes... not a really an attribute?To: NULL Date: 5/11/2007 10:58:00 PM
OK, been struggling with this one... Basically, I want to take an XML which
may include namespaces, and reformat it into a proprietary XML format:
Here's an example:
SOURCE XML:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://lartermi.org/" />
</soap:Body>
</soap:Envelope>
DESIRED OUTPUT XML:
<nameValues>
<nameValue name="url" dataType="attribute" value="" />
<nameValue dataType="element" name="soap:Envelope" value="">
<nameValue dataType="attribute" name="xmlns:xsi"
value="http://www.w3.org/2001/XMLSchema-instance"/>
<nameValue dataType="attribute" name="xmlns:xsd"
value="http://www.w3.org/2001/XMLSchema"/>
<nameValue dataType="attribute" name="xmlns:soap"
value="http://schemas.xmlsoap.org/soap/envelope"/>
<nameValue dataType="element" name="soap:Body" value="">
<nameValue dataType="element" name="HelloWorld" value="" />
</nameValue>
</nameValue>
</nameValues>
Here's the XSL I';ve got so far that gets me very close -- Note, the source
XML gets surounded by <XML2ExampleFld><EXAMPLERoot> tags prior to submission
to the XSL file
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:variable name="StoreValues">
<xsl:value-of select="//EXAMPLEStoreValues"/>
</xsl:variable>
<xsl:template match="/">
<rules>
<value>
<request verb="Send.postRq" get="@status">
<onFailure value=""/>
<modifySession value=""/>
<usesSession value=""/>
<default value=""/>
<nameValues>
<nameValue name="url" dataType="attribute">
<xsl:attribute name="value">
<xsl:value-of select="/XML2ExampleFld/EXAMPLEUrl"/>
</xsl:attribute>
</nameValue>
<xsl:apply-templates select="/XML2ExampleFld/EXAMPLERoot/*"/>
</nameValues>
</request>
</value>
</rules>
</xsl:template>
<xsl:template match="*">
<nameValue dataType="element" >
<xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
<xsl:attribute name="value">
<xsl:if test="$StoreValues='True' and text() != ''">
<xsl:value-of select="text()"/>
</xsl:if>
</xsl:attribute>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="*"/>
</nameValue>
</xsl:template>
<xsl:template match="@*">
<nameValue dataType="attribute">
<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="$StoreValues='True' ">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</nameValue>
</xsl:template>
</xsl:stylesheet>
Thanks for any assistance...
Michael
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
