用xslt和SSIS动态地过滤xml子元素 [英] Filter dynamically xml child element with xslt with SSIS
问题描述
我在Database中有一个语言表。我希望使用xslt过滤器子元素< Name>
,这取决于我的表格内容。
我在SSIS项目中。
1 / I创建一个名为Filter的变量,并将一个Foreach ADO枚举器放置在变量IdLang中
$ b $ 2使用表达式任务:
@ UserID:@ [User :: Filter] == 0?@langid =+(DT_WSTR,2)@ [User :: IdLang]:@ [User :: Filter] + 或@ langid =+(DT_WSTR,2)@ [User :: IdLang])
$ b <3>有一个xslt文件,我把它放在名为xslt的变量中:
< xsl:stylesheet version =1.0的xmlns:XSL = http://www.w3.org/1999/XSL/Transform > < xsl:output method =xmlencoding =UTF-8indent =yes/> < xsl:template match =/ ICECAT-interface> < xsl:apply-templates select =Response/> < / XSL:模板> < xsl:template match =Response> < xsl:apply-templates select =SuppliersList/> < / XSL:模板> < xsl:template match =SuppliersList> < XSL:复制和GT; < xsl:apply-templates select =供应商/> < / XSL:复制和GT; < / XSL:模板> < xsl:template match =供应商> <供应商> < xsl:copy-of select =@ ID | @LogoLowPic | @Name/> < xsl:attribute name =langid> < xsl:value-of select =1/> < / XSL:属性> < /供应商> < xsl:apply-templates select =名称/名称/> < / XSL:模板> < xsl:template match =Name [###]> <供应商> < xsl:copy-of select =../../@ID | ../../ @ LogoLowPic | @langid | @Name/> < /供应商> < / XSL:模板> < / XSL:样式表>
4 / ANd最后我使用脚本任务
< pre $
Dim filtr As String = Dts.Variables(User :: Filter)。Value
Dim Schem = Dts.Variables(User :: Xslt ).Value.ToString.Replace(###,filtr)
Dim xslt As New XslCompiledTransform()
xslt.Load(New XmlTextReader(New IO.StringReader(Schem)))
Dim settings As New Xml.XmlReaderSettings()
settings.DtdProcessing = Xml.DtdProcessing.Parse
Dim SourcePath As String = ???
Dim source As Xml.XmlReader = Xml.XmlReader.Create(SourcePath,settings)
Dim DestinationPath As String = ???
Dim Destination Xml.XmlWriter = Xml.XmlWriter.Create(DestinationPath)
xslt.Transform(source,Destination)
我希望它可以帮助别人。
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 according to the child node
I've in Database a table of language. And I want with xslt filter child elements <Name>
depending of my table content.
I'm in SSIS project.
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:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="/ICECAT-interface"> <xsl:apply-templates select="Response"/> </xsl:template> <xsl:template match="Response"> <xsl:apply-templates select="SuppliersList"/> </xsl:template> <xsl:template match="SuppliersList"> <xsl:copy> <xsl:apply-templates select="Supplier"/> </xsl:copy> </xsl:template> <xsl:template match="Supplier"> <Supplier> <xsl:copy-of select="@ID|@LogoLowPic|@Name"/> <xsl:attribute name="langid"> <xsl:value-of select="1"/> </xsl:attribute> </Supplier> <xsl:apply-templates select="Names/Name"/> </xsl:template> <xsl:template match="Name[###]"> <Supplier> <xsl:copy-of select="../../@ID|../../@LogoLowPic|@langid|@Name" /> </Supplier> </xsl:template> </xsl:stylesheet>
4/ ANd finally I use script task
Dim filtr As String = Dts.Variables("User::Filter").Value
Dim Schem = Dts.Variables("User::Xslt").Value.ToString.Replace("###", filtr)
Dim xslt As New XslCompiledTransform()
xslt.Load(New XmlTextReader(New IO.StringReader(Schem)))
Dim settings As New Xml.XmlReaderSettings()
settings.DtdProcessing = Xml.DtdProcessing.Parse
Dim SourcePath As String = ???
Dim source As Xml.XmlReader = Xml.XmlReader.Create(SourcePath, settings)
Dim DestinationPath As String = ???
Dim Destination As Xml.XmlWriter = Xml.XmlWriter.Create(DestinationPath)
xslt.Transform(source, Destination)
I Hope It can helping someone.
这篇关于用xslt和SSIS动态地过滤xml子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!