XSL and transformNodeToObject

M

mtugnoli

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
 
M

Martin Honnen

mtugnoli said:
<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

</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.
 
M

mtugnoli

mtugnoli said:
<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

</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.


Hey Martin,

All run Ok

Thank for your Help

mtugnoli
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top