Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: nested xsl:for-each with document function

From: Cozmo <C_o_z_m_o@---.-->
To: 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!!!!


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent