[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: localization techniques and code review
Haroon, > 1. Am I on the right track? What about the use of nested > <xsl:for-each select="document('localization.xml')"> Looks like you are. There's one small error, in that you're using xsl:param immediately within an xsl:for-each - that needs to be an xsl:variable instead. The other small thing is that having assigned the root node of the 'localization.xml' document to the 'trans' variable, you may as well use it again instead of reaccessing the document in the xsl:for-each. You also don't have to search all the root descendants for the 'field' elements: they're all direct children of 'page' (at least in this example). In other words, change it to: <xsl:for-each select="field"> <xsl:variable name="field" select="." /> <xsl:value-of select="$field" /> <h1> <xsl:for-each select="$trans"> <xsl:value-of select="key('translate',concat($field,'-',$selectLang))" /> </xsl:for-each> </h1> </xsl:for-each> The nested xsl:for-each is necessary. The key() function that you use is scoped by the current node: it only looks for nodes within the current document. In the outer xsl:for-each, the current document is your source XML. You need to change it to the localization.xml document to use the key to retrieve information quickly from it. > 2. What if I need to re-print the table again? Could I have somehow > stored the results of the document() call to be able to reuse it at > a later stage? Not within XSLT. It really depends on your set up, how you're processing the XSLT on the server. It may be possible for the server to keep the DOM for the localization.xml document cached so that it doesn't have to parse it each time. Perhaps a Cocoon person can give you a better answer. Sorry I can't be more help, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|