Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Namespace Nodes... not a really an attribute?

From: "ComCastNews" <mlarter@-------.--->
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 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent