Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Generating Attribute Excerpts [Thread Next] Re: Generating Attribute ExcerptsTo: NULL Date: 4/6/2005 12:47:00 PM Radek Jedrasiak wrote:
> i need some xslt support for a system which has to generate several xml
> file out of one input file.
>
> The input file contains the data for lets say several languages,
> and the generated output files should contain the info for just one
> language.
>
> So the input looks like
>
> <Input>
> <E i="1" a1="1" a2="2" b1="y" b2="x" />
> <E i="2" a1="1" a2="2" b1="w" b2="v"/>
> <R i="1" u1="j" u2="k" />
> <R i="1" u1="q" u2="s" />
> </Input>
>
> the desired output FILES are:
>
> <Output>
> <E i="1" a1="1" b1="y" />
> <E i="2" a1="1" b1="w"/>
> <R i="1" u1="j" />
> <R i="1" u1="q" />
> </Output>
>
> AND
>
> <Output>
> <E i="1" a2="2" b2="x" />
> <E i="2" a2="2" b2="v"/>
> <R i="1" u2="k" />
> <R i="1" u2="s" />
> </Output>
>
> The desired xslt transformation should have a parameter which defines which
> version of the excerpt to create ("1" or "2" in this example)
>
> Please note that the attributes have "1" and "2" as suffixes for the
> different language attributes,
> and this could be used to write the xslt so it can handle the attributes for
> one language in a generic way.
You can try something like
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="lang-code" select="1"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Input">
<Output>
<xsl:apply-templates select="@*|node()"/>
</Output>
</xsl:template>
<xsl:template match="@*">
<xsl:variable name="last-char" select="substring(name(),
string-length(name()))"/>
<!-- if attribute name doesn't end with a number or that
number matches language code - output it -->
<xsl:if test="(number($last-char) != number($last-char)) or
($last-char = $lang-code)">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
If your language code can be > 9, you need to extend matching, but you
get the idea.
--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
