Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How do get the root node?

From: "tshad" <tshad@----------.--->
To: NULL
Date: 3/3/2008 10:32:00 AM

I forgot to add the xlst file I am using:

Below:

"tshad" <tshad@d...> wrote in message 
news:%232Imb5ZeIHA.4744@T......
>
> "Martin Honnen" <mahotrash@y...> wrote in message 
> news:uvSk87GeIHA.5552@T......
>> tshad wrote:
>>
>>> I want the file to work as it does not but replace the 
>>> <dataset></dataset> tags with whatever the root nodes were.
>>
>>
>> Can you show us an example of your XML input? If you want to copy the 
>> root element you can do that with
>>   <xsl:template match="/*">
>>     <xsl:copy>
>>       <xsl:apply-templates/>
>>     </xsl:copy>
>>   </xsl:template>
>> but without seeing the XML input it is difficult to suggest what else 
>> needs to be adapted in the stylesheet.
>>
>
> Following is a snippet of the xml file.
>
> At the moment we end up with 2 tables (form and attachments) with my 
> dataset from this xsl sheet and the root node will end up with 
> <data></data> as the root.
>
> I want to change that to put whatever is in the root of the XML file 
> (Argus-Report in this example) as the root of the transformation so I 
> should see something like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Argus-Report>
>    <form>
>   </form>
>   <attachment>
>   </attachment>
> </Argus-Report>
>
> At the moment I am getting:
> <?xml version="1.0" encoding="UTF-8"?>
> <dataset>
>    <form>
>   </form>
>   <attachment>
>   </attachment>
> </dataset>
>
> The XML file.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Argus-Report>
> <approval>
>  <data>
>   <form name="order" primary="false">
>    <tag name="NAME.1" flags="1" format="4096">Marco</tag>
>   </form>
>   <form name="lot" primary="false">
>    <tag name="NAME.2" flags="1" format="4096">John Doe</tag>
>   </form>
>   <form name="title" primary="false">
>    <tag name="APPR_NAME.1" flags="1" format="12288">John Doe</tag>
>   </form>
>   <form name="13781" primary="true">
>    <section type="subject" number="0">
>     <tag name="CITY.1" flags="1" format="4096">Irvine</tag>
>     <tag name="STATE.1" flags="1" format="4096">CA</tag>
>     <tag name="COUNTY.1" flags="1" format="4096">Orange</tag>
>    </section>
>    <section type="sales" number="1">
>     <tag name="GS_AGE.1" flags="1" format="4096">1</tag>
>     <tag name="GS_SITE.1" flags="1" format="102">12000</tag>
>     <tag name="GS_VIEW.1" flags="1" format="4096">ocean</tag>
>    </section>
>    <section type="sales" number="2">
>     <tag name="GS_AGE.1" flags="1" format="4096">1</tag>
>     <tag name="GS_SITE.1" flags="1" format="4096">15000</tag>
>     <tag name="GS_VIEW.1" flags="1" format="4096">none</tag>
>    </section>
>   </form>
>   <form name="subjectphotopage" primary="false">
>    <section type="subject" number="0">
>     <tag name="AS_OF_DATE.1" flags="1" format="4096">December 12, 
> 2007</tag>
>     <tag name="DATE_SIGNED.1" flags="0" format="0">12/12/2007</tag>
>     <tag name="ESTIMATED.1" flags="8" format="4128">1000000</tag>
>    </section>
>    <tag name="PHOTO_FILE.1" flags="4096" 
> format="12288">ancestor::approval/attachments/attachment[1]</tag>
>    <tag name="PHOTO_FILE.2" flags="4096" 
> format="12288">ancestor::approval/attachments/attachment[2]</tag>
>   </form>
>  </data>
>   <attachments>
>    <attachment key="db8d208f-b049-4caa-bac0-eeb4cf9007d6" type="photo" 
> label=" Sale #1">
>    <image>
>     <binary xmlns:dt="urn:schemas-microsoft-com:datatypes" 
> dt:dt="bin.base64" format="jpeg">
>    </image>
>    <thumbnail>
>     <binary xmlns:dt="urn:schemas-microsoft-com:datatypes" 
> dt:dt="bin.base64" format="jpeg">
>    </thumbnail>
>   </attachment>
>    <attachment key="db8d208f-b049-4caa-bac0-eeb4cf9007d6" type="photo" 
> label=" Sale #1">
>    <image>
>     <binary xmlns:dt="urn:schemas-microsoft-com:datatypes" 
> dt:dt="bin.base64" format="jpeg">
>    </image>
>    <thumbnail>
>     <binary xmlns:dt="urn:schemas-microsoft-com:datatypes" 
> dt:dt="bin.base64" format="jpeg">
>    </thumbnail>
>   </attachment>
>  </attachments>
> </approval>
> </Argus-Report>
>

The XLST file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <xsl:output method="xml" indent="yes"/>
 <xsl:template match="/">
  <root_node>
   <dataset>
    <xsl:apply-templates>
     <xsl:sort select="form/@primary" order="descending"/>
    </xsl:apply-templates>
   </dataset>
  </root_node>
 </xsl:template>
 <xsl:template match="tag">
  <form>
   <sectionNumber>
    <xsl:value-of select="ancestor::section/@number"/>
   </sectionNumber>
   <primary>
    <xsl:value-of select="ancestor::form/@primary"/>
   </primary>
   <formName>
    <xsl:value-of select="ancestor::form/@name"/>
   </formName>
   <tagName>
    <xsl:value-of select="@name"/>
   </tagName>
   <flags>
    <xsl:if test="not(@flags)">
     <xsl:attribute name="xsi:nil">true</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@flags"/>
   </flags>
   <format>
    <xsl:if test="not(@format)">
     <xsl:attribute name="xsi:nil">true</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@format"/>
   </format>
   <value>
    <xsl:value-of select="."/>
   </value>
  </form>
 </xsl:template>
  <xsl:template match="attachments/attachment">
    <attachment>
      <key>
        <xsl:value-of select="@key"/>
      </key>
      <type>
        <xsl:value-of select="@type"/>
      </type>
      <label>
        <xsl:value-of select="@label"/>
      </label>
      <format>
        <xsl:value-of select="image/binary/@format"/>
      </format>
      <image>
        <xsl:value-of select="image/binary/text()"/>
      </image>
      <thumbnailFormat>
        <xsl:value-of select="thumbnail/binary/@format"/>
      </thumbnailFormat>
      <thumbnailImage>
        <xsl:value-of select="thumbnail/binary/text()"/>
      </thumbnailImage>
    </attachment>
  </xsl:template>
</xsl:stylesheet>


> The other thing I need to figure out is how to get the value from the 
> attributes "xmlns:dt" and "dt:dt" in the binary tag.
>
> Thanks,
>
> Tom
>
>> -- 
>>
>> Martin Honnen --- MVP XML
>> http://JavaScript.FAQTs.com/
>
> 




transparent
Print
Mail
Digg
delicious
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