Skip to content Skip to sidebar Skip to footer

Filter Dynamically Xml Child Element With Xslt With Ssis

I've a big xml file from ICECAT. And I want take only some informations. It's in the following of this subject how transform xml document with xslt to duplicate output lines accord

Solution 1:

1/I create a variable named Filter and a Foreach ADO Enumerator putting enuration in variable IdLang

2/ Use a expression task with this expression : @[User::Filter]=( LEN( @[User::Filter] ) ==0 ? "@langid=" + (DT_WSTR, 2) @[User::IdLang] : @[User::Filter] + " or @langid=" + (DT_WSTR, 2)@[User::IdLang] )

3/ In old subject, I've an xslt file, what I put in a variable named "xslt":

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:outputmethod="xml"encoding="UTF-8"indent="yes"/><xsl:templatematch="/ICECAT-interface"><xsl:apply-templatesselect="Response"/></xsl:template><xsl:templatematch="Response"><xsl:apply-templatesselect="SuppliersList"/></xsl:template><xsl:templatematch="SuppliersList"><xsl:copy><xsl:apply-templatesselect="Supplier"/></xsl:copy></xsl:template><xsl:templatematch="Supplier"><Supplier><xsl:copy-ofselect="@ID|@LogoLowPic|@Name"/><xsl:attributename="langid"><xsl:value-ofselect="1"/></xsl:attribute></Supplier><xsl:apply-templatesselect="Names/Name"/></xsl:template><xsl:templatematch="Name[###]"><Supplier><xsl:copy-ofselect="../../@ID|../../@LogoLowPic|@langid|@Name" /></Supplier></xsl:template></xsl:stylesheet>

4/ ANd finally I use script task

Dim filtr AsString = Dts.Variables("User::Filter").Value 

        Dim Schem = Dts.Variables("User::Xslt").Value.ToString.Replace("###", filtr)
        Dim xslt AsNew XslCompiledTransform()
        xslt.Load(New XmlTextReader(New IO.StringReader(Schem)))
         Dim settings AsNew Xml.XmlReaderSettings()
        settings.DtdProcessing = Xml.DtdProcessing.Parse
        Dim SourcePath AsString = ???
        Dim source As Xml.XmlReader = Xml.XmlReader.Create(SourcePath, settings)

        Dim DestinationPath AsString = ???
        Dim Destination As Xml.XmlWriter = Xml.XmlWriter.Create(DestinationPath)

        xslt.Transform(source, Destination)

I Hope It can helping someone.

Post a Comment for "Filter Dynamically Xml Child Element With Xslt With Ssis"