Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: nested xsl:for-each with document function [Thread Next] Re: nested xsl:for-each with document functionTo: NULL Date: 9/10/2009 6:09:00 AM On Sep 10, 3:01=A0pm, Martin Honnen <mahotr...@yahoo.de> wrote:
> Cozmo wrote:
> > No I have one input document and want to transform it via saxon. But I
> > need data from a second one so I use the document function. (merge the
> > information)
>
> > First input file:
>
> > =A0 =A0<record>
> > =A0 =A0 =A0 =A0 =A0 =A0<c2>AD</c2>
> > =A0 =A0 =A0 =A0 =A0 =A0<c3>AS</c3>
> > =A0 =A0 =A0 =A0 =A0 =A0<cn>002</cn>
> > =A0 =A0 =A0 =A0 =A0 =A0<short.name>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<lg.vers lg=3D"ss">text</lg.vers=
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<lg.vers lg=3D"tt">text</lg.vers=
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"ts">text=
</lg.vers>
> > ....
>
> > the file which I import via the document function:
>
> > =A0 =A0<record>
> > =A0 =A0 =A0 =A0 =A0 =A0<short.name>test</short.name>
> > =A0 =A0 =A0 =A0 =A0 =A0<long.name>text</long.name>
> > =A0 =A0 =A0 =A0 =A0 =A0<iso.code2>AD</iso.code2>
> > =A0 =A0 =A0 =A0 =A0 =A0<source.lang>bg</source.lang>
> > =A0 =A0</record>
> > =A0 =A0<record>
> > =A0 =A0 =A0 =A0 =A0 =A0<short.name>test</short.name>
> > =A0 =A0 =A0 =A0 =A0 =A0<long.name>text</long.name>
> > =A0 =A0 =A0 =A0 =A0 =A0<iso.code2>AD</iso.code2>
> > =A0 =A0 =A0 =A0 =A0 =A0<source.lang>tt</source.lang>
> > =A0 =A0</record>
> > =A0 =A0<record>
> > =A0 =A0 =A0 =A0 =A0 =A0<short.name>test</short.name>
> > =A0 =A0 =A0 =A0 =A0 =A0<long.name>text</long.name>
> > =A0 =A0 =A0 =A0 =A0 =A0<iso.code2>DZ</iso.code2>
> > =A0 =A0 =A0 =A0 =A0 =A0<source.lang>bg</source.lang>
> > =A0 =A0</record>
>
> > In the second file are additional information which I want to Add as a
> > node. Example:
> > =A0<lg.vers lg=3D"bg">test</lg.vers> =A0should be added.
>
> > As you can see first restriction c2 =3D iso.code2.
> > Second restriction add elemnt only if source.lang doesnt exist list.
> > ( So, @lg =3D tt shouldn't be added)
>
> Assuming the primary input is
>
> <root>
> =A0 =A0 =A0 =A0 <record>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <c2>AD</c2>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <c3>AS</c3>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <cn>002</cn>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <short.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"ss">text</=
lg.vers>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"tt">text</=
lg.vers>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<lg.vers lg=3D"ts">tex=
t</lg.vers>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</short.name>
> =A0 =A0 =A0 =A0 =A0</record>
> </root>
>
> and the second XML document is
>
> <root>
> =A0 =A0 =A0 =A0 <record>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <short.name>test</short.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <long.name>text</long.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <iso.code2>AD</iso.code2>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <source.lang>bg</source.lang>
> =A0 =A0 =A0 =A0 </record>
> =A0 =A0 =A0 =A0 <record>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <short.name>test</short.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <long.name>text</long.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <iso.code2>AD</iso.code2>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <source.lang>tt</source.lang>
> =A0 =A0 =A0 =A0 </record>
> =A0 =A0 =A0 =A0 <record>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <short.name>test</short.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <long.name>text</long.name>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <iso.code2>DZ</iso.code2>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <source.lang>bg</source.lang>
> =A0 =A0 =A0 =A0 </record>
> </root>
>
> then this stylesheet copies everything from the primary input document
> and in the short.name element of each record elements adds new lg.vers
> elements:
>
> <xsl:stylesheet
> =A0 =A0xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> =A0 =A0version=3D"1.0">
>
> =A0 =A0<xsl:strip-space elements=3D"*"/>
> =A0 =A0<xsl:output indent=3D"yes"/>
>
> =A0 =A0<xsl:param name=3D"sd" select=3D"'test2009091002.xml'"/>
> =A0 =A0<xsl:variable name=3D"srs" select=3D"document($sd)/root/record"/>
>
> =A0 =A0<xsl:template match=3D"@* | node()">
> =A0 =A0 =A0<xsl:copy>
> =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"@* | node()"/>
> =A0 =A0 =A0</xsl:copy>
> =A0 =A0</xsl:template>
>
> =A0 =A0<xsl:template match=3D"short.name">
> =A0 =A0 =A0<xsl:copy>
> =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"@* | node()"/>
> =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"$srs[iso.code2 =3D current(=
)/../c2 and
> not(source.lang =3D current()/lg.vers/@lg)]" mode=3D"new"/>
> =A0 =A0 =A0</xsl:copy>
> =A0 =A0</xsl:template>
>
> =A0 =A0<xsl:template match=3D"record" mode=3D"new">
> =A0 =A0 =A0<lg.vers lg=3D"{source.lang}"><xsl:value-of
> select=3D"short.name"/></lg.vers>
> =A0 =A0</xsl:template>
>
> </xsl:stylesheet>
>
> creates the output
>
> <root>
> =A0 =A0 <record>
> =A0 =A0 =A0 =A0<c2>AD</c2>
> =A0 =A0 =A0 =A0<c3>AS</c3>
> =A0 =A0 =A0 =A0<cn>002</cn>
> =A0 =A0 =A0 =A0<short.name>
> =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"ss">text</lg.vers>
> =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"tt">text</lg.vers>
> =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"ts">text</lg.vers>
> =A0 =A0 =A0 =A0 =A0 <lg.vers lg=3D"bg">test</lg.vers>
> =A0 =A0 =A0 =A0</short.name>
> =A0 =A0 </record>
> </root>
>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen
> =A0 =A0 =A0 =A0http://msmvps.com/blogs/martin_honnen/
Amazing it is working. Wonderful you helped a lot! Quite happy
know :-)
Thanks a lot!!!!
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
