Re: generating tags using xslt

Axel Hecht <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
Pierre-Yves wrote:
> hello,
> I have a xml files that looks like :
> 
> <record name="myRecord">
>     <item name="PageName">
>         <value>myPage</value>
>     </item>
>     <item name="Title_EN">
>         <value>english title</value>
>     </item>
>     <item name="Title_FR">
>         <value>french title</value>
>     </item>
>     <item name="Paragraph_EN">
>         <value>
>             <item name="SubParagraph_EN">
>                 <value>sub-paragraph 1 (english)</value>
>             </item>
>             <item name="SubParagraph_EN">
>                 <value>sub-paragraph 2 (english)</value>
>             </item>
>         </value>
>     </item>
>     <item name="Paragraph_FR">
>         <value>
>             <item name="SubParagraph_FR">
>                 <value>sub-paragraph 1 (french)</value>
>             </item>
>         </value>
>     </item>
> </record>
> 
> and I would like to transform it like this :
> 
> <record name="myRecord">
>     <item name="common">
>         <value>
>             <item name="PageName">
>                 <value>myPage</value>
>             </item>
>         </value>
>     </item>
>     <item name="english">
>         <value>
>             <item name="Title">
>                 <value>english title</value>
>             </item>
>             <item name="Paragraph">
>                 <value>
>                     <item name="SubParagraph">
>                         <value>sub-paragraph 1 (english)</value>
>                     </item>
>                     <item name="SubParagraph">
>                         <value>sub-paragraph 2 (english)</value>
>                     </item>
>                 </value>
>             </item>
>         </value>
>     </item>
>     <item name="french">
>         <value>
>             <item name="Title">
>                 <value>french title</value>
>             </item>
>             <item name="Paragraph">
>                 <value>
>                     <item name="SubParagraph">
>                         <value>sub-paragraph 1 (french)</value>
>                     </item>
>                 </value>
>             </item>
>         </value>
>     </item>
> </record>
> 
> The goal, is to put all items that ends with _EN into <item name="english">,
> all items that ends with _FR into <item name="french">, and all remaining
> items into <item name="common">.
> 
> Someone told me I can easily do this with XSLT.
> I started by mapping some fields "1 to 1" but since all <items> elements
> have the same structure <item name="XXXX"><value>YYY</value></item> I would
> like to know if it's possible to write a kind of function that could get
> arguments or use some variables to simplify the code.
> 

look at http://www.w3.org/TR/xpath#section-String-Functions. And I 
suggest that you get rid of the awkward french stuff and use 
xml:lang="fr", instead.

No reason to not fix it right now, I hope

Axel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.