XML into dataset

Hello. I have very loosy knowledge in XSLT and maybe this is a reason. However i am stack with the following problem:
I have an XML like
<SHOWS>
<SHOW DISPLAYED='0'/>
<SHOW DISPLAYED='0'/>
<SHOW DISPLAYED='1'/>
<SHOW DISPLAYED='1'/>
<SHOW DISPLAYED='0'/>
</SHOWS>
I need to upload into dataset only those SHOW elements which DISPLAYED attribute is 1. Reading MSDN documentation i have found that the only logical way is using XslCompiledTransform. There are two problems with using this class. First it creates XmlWriter while i need XmlReader for which means i need to enter into complicated transformation XmlWriter -> StringBuilder -> Stream/TextReader
and second the XSLT i have does not work
( it is a 3rd attempt
< xml version="1.0" encoding="ISO-8859-1" >
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:element name="SHOWS">
<xsl:for-each select="/SHOWS/SHOW[@DISPLAYED=1]">
<xsl:element name="SHOW">
<xsl:value-of select="SHOW" />
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>

</xsl:transform>)

Can anybody suggest another way to achieve the goal or effective XSLT



Answer this question

XML into dataset

  • sagittarian

    Minherz wrote:
    Hello. I have very loosy knowledge in XSLT and maybe this is a reason. However i am stack with the following problem:
    I have an XML like
    <SHOWS>
    <SHOW DISPLAYED='0'/>
    <SHOW DISPLAYED='0'/>
    <SHOW DISPLAYED='1'/>
    <SHOW DISPLAYED='1'/>
    <SHOW DISPLAYED='0'/>
    </SHOWS>
    I need to upload into dataset only those SHOW elements which DISPLAYED attribute is 1.

    Simply use the identity transformation and add one template e.g.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="xml"/>

    <xsl:template match="@* | node()">

    <xsl:copy>

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

    </xsl:copy>

    </xsl:template>

    <xsl:template match="SHOW[@DISPLAYED = '0']"/>

    </xsl:stylesheet>

    that way any nodes besides the SHOW elements with DISPLAYED attribute value '0' are copied from the input document to the result document of the transformation.



  • XML into dataset