|
| How do get the root node? |
 |
Mon, 25 Feb 2008 16:40:10 -080 |
I have been displaying a new root node <dataset> with my transformations.
How do I get the file to use the old root node in my transformation?
How would I change the following xslt file to accomplish that?
<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="/">
<dataset>
<xsl:apply-templates>
<xsl:sort select="form/@primary"
order="descending"/>
</xsl:apply-templates>
</dataset>
</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>
I want the file to work as it does not but replace the
<dataset></dataset>
tags with whatever the root nodes were.
Thanks,
Tom
|
| Post Reply
|
| Re: How do get the root node? |
 |
Tue, 26 Feb 2008 09:09:15 +010 |
Użytkownik "tshad" <tshad@dslextreme.com> napisał w wiadomości
news:eAIOxBBeIHA.748@TK2MSFTNGP04.phx.gbl...
>How do get the root node?
/*
What exactly do you want to do?
--
td
|
| Post Reply
|
| Re: How do get the root node? |
 |
Tue, 26 Feb 2008 12:58:57 +010 |
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.
--
Martin Honnen --- MVP XML
|
| Post Reply
|
| Re: How do get the root node? |
 |
Wed, 27 Feb 2008 16:08:31 -080 |
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:uvSk87GeIHA.5552@TK2MSFTNGP06.phx.gbl...
> 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 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/
|
| Post Reply
|
| Re: How do get the root node? |
 |
Mon, 3 Mar 2008 10:31:58 -0800 |
I forgot to add the xlst file I am using:
Below:
"tshad" <tshad@dslextreme.com> wrote in message
news:%232Imb5ZeIHA.4744@TK2MSFTNGP06.phx.gbl...
>
> "Martin Honnen" <mahotrash@yahoo.de> wrote in message
> news:uvSk87GeIHA.5552@TK2MSFTNGP06.phx.gbl...
>> 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/
>
>
|
| Post Reply
|
|
|
|
|
|
|
|
|
|