XSL and transformNodeToObject

Discussion in 'XML' started by mtugnoli, Mar 27, 2007.

  1. mtugnoli

    mtugnoli Guest

    I've found a sample on http://msdn2.microsoft.com/en-us/library/ms766561.aspx

    to filter a .XML
    ex.


    <?xml version="1.0"?>
    <COLLECTION dateCreated="01-04-2000">
    <BOOK>
    <TITLE>Splish Splash</TITLE>
    <AUTHOR>Paula Thurman</AUTHOR>
    <PUBLISHER>Scootney</PUBLISHER>
    <PRICE>250</PRICE>
    </BOOK>
    <BOOK>
    <TITLE Editor="Hoepli">Lover Birds2</TITLE>
    <AUTHOR>Cynthia Randall</AUTHOR>
    <PUBLISHER>Lucerne Publishing</PUBLISHER>
    <PRICE>200</PRICE>
    </BOOK>
    <BOOK>
    <TITLE>The Sundered Grail</TITLE>
    <AUTHOR>Eva Corets</AUTHOR>
    <PUBLISHER>Lucerne Publishing</PUBLISHER>
    <PRICE>100</PRICE>
    </BOOK>
    </COLLECTION>


    file .xsl


    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform">
    <xsl:template match="/">
    <LowPriceBooks>
    <xsl:for-each select="//COLLECTION/BOOK[not(PRICE >'220')]">
    <xsl:copy>
    <xsl:apply-templates select="*"/>
    </xsl:copy>
    </xsl:for-each>
    </LowPriceBooks>
    </xsl:template>
    <xsl:template match="*">
    <xsl:copy>
    <xsl:apply-templates />
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>


    the essential part on VB


    ' Parse results into a result DOM Document.
    Source.transformNodeToObject stylesheet, result


    where Source is not filtred .XML and stylesheet is .xsl file where
    result is .XML
    processed (filtred) with PRICE > 220


    considering I don't know very well XML,

    All work fine but after the processing the node

    <TITLE Editor="Hoepli">Lover Birds2</TITLE>


    the property Editor="Hoepli" is lost !!

    can I change the .xls file to copy also properties ?

    I hope someone can help me ..


    mtugnoli
    mtugnoli, Mar 27, 2007
    #1
    1. Advertising

  2. mtugnoli wrote:

    > <xsl:template match="/">
    > <LowPriceBooks>
    > <xsl:for-each select="//COLLECTION/BOOK[not(PRICE >'220')]">
    > <xsl:copy>
    > <xsl:apply-templates select="*"/>
    > </xsl:copy>
    > </xsl:for-each>


    Instead of the xsl:for-each simply use

    <xsl:apply-templates select="//COLLECTION/BOOK[not(PRICE > 220)]"/>


    > </LowPriceBooks>
    > </xsl:template>
    > <xsl:template match="*">
    > <xsl:copy>
    > <xsl:apply-templates />
    > </xsl:copy>
    > </xsl:template>


    then instead of the above template use

    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    that way the attributes get copied too.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 27, 2007
    #2
    1. Advertising

  3. mtugnoli

    mtugnoli Guest

    On 27 Mar, 15:10, Martin Honnen <> wrote:
    > mtugnoli wrote:
    > > <xsl:template match="/">
    > > <LowPriceBooks>
    > > <xsl:for-each select="//COLLECTION/BOOK[not(PRICE >'220')]">
    > > <xsl:copy>
    > > <xsl:apply-templates select="*"/>
    > > </xsl:copy>
    > > </xsl:for-each>

    >
    > Instead of the xsl:for-each simply use
    >
    > <xsl:apply-templates select="//COLLECTION/BOOK[not(PRICE > 220)]"/>
    >
    > > </LowPriceBooks>
    > > </xsl:template>
    > > <xsl:template match="*">
    > > <xsl:copy>
    > > <xsl:apply-templates />
    > > </xsl:copy>
    > > </xsl:template>

    >
    > then instead of the above template use
    >
    > <xsl:template match="@* | node()">
    > <xsl:copy>
    > <xsl:apply-templates select="@* | node()"/>
    > </xsl:copy>
    > </xsl:template>
    >
    > that way the attributes get copied too.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/



    Hey Martin,

    All run Ok

    Thank for your Help

    mtugnoli
    mtugnoli, Mar 27, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karsten Weinert
    Replies:
    3
    Views:
    985
    Karsten Weinert
    Jul 5, 2004
  2. Replies:
    1
    Views:
    3,571
    A. Bolmarcich
    May 27, 2005
  3. Anthony Jones
    Replies:
    6
    Views:
    270
    Anthony Jones
    Aug 13, 2008
  4. Anthony Jones
    Replies:
    4
    Views:
    206
    Chris
    Dec 19, 2008
  5. tuser
    Replies:
    4
    Views:
    305
    tuser
    Feb 19, 2006
Loading...

Share This Page