Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Generating Attribute Excerpts

From: "Oleg Tkachenko [MVP]" <oleg@--!----!---------------.--->
To: 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


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