[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Complicated transformation step when using locali

Subject: Re: Complicated transformation step when using localization
From: knocte <knocte@xxxxxxxxx>
Date: Thu, 13 Oct 2005 10:11:32 +0200
transformation step
knocte wrote:
Hello list!
I am trying to make a transformation step but I can't get it to work!

I will receive an XML document with many nodes. Some of them may contain the attribute "translate-attrs":

<...>
<img src="myURI" alt="translate me" title="me too" translate-attrs="alt title" />
<...>


I want to select all the nodes that have this attribute and replace the content of the attributes with the content of an external file, like this:

<external-dictionary>
 <text key="translate me">Translate me, in other language</text>
 <text key="me too">Me too, in other idiom</text>
</external-dictionary>

Expected final XML result would be:

<...>
<img src="myURI" alt="Translate me, in other language" title="Me too, in other idiom" />
<...>



So first we want to match all the nodes that have this attribute:


<xsl:template match="*[@translate-attrs]">


Then we want to copy all attributes except the one mentioned:


<xsl:copy-of select="@*[not (local-name()='translate-attrs')]" />

Now I want to do a for-each part which captures all of the terms separated by spaces that are contained in the translate-attrs attribute, and make an attribute by each, with the content of the external XML file, but I can't achieve it! It would be something like:

<xsl:for-each select"@translate-attrs">
<xsl:attribute name=".">
<xsl:value-of select="document($myxml)//external-dictionary/text[@key = current()/@{.}]" />
</xsl:attribute>
</xsl:for-each>


Finally, we need to copy the rest of the child elements:

 <xsl:apply-templates />
</xsl:template>


Does anybody know how can I make the middle part, the most difficult one? Any help will be appreciated!


Regards,

Andrew [ knocte ]

After some more research I think I must use a combination of two techniques:


a) Recursive named template (example: "String split into elements" -> http://www.dpawson.co.uk/xsl/sect2/N7240.html#d9570e343 ).
b) <xsl:key> (example: "Replacing a string by another which is found by reference in the same XML document" -> http://www.dpawson.co.uk/xsl/sect2/N7240.html#d9570e109 ).


Am I correct?

Thanks in advance.

Andrew [ knocte ]

--

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.