XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Max MandersSubject: Simplify This... Am I Missing Something?
Author: Max Manders
Date: 14 May 2007 07:14 AM
I am using FOP to convert a fairly complex XML document to PDF. In essence, the structure can be quite nested at times but ultimately I am outputting key/value pairs using XSL-FO like 'key: value'.

The element names do not have any attributes so in order to get a human readable version of a tag I have a lookup file consisting of lots of variables that convert something like ns_element_name to Element Name. This is done using the templates below.

<xsl:template match="<long list of | separated tags - more than 20 and growing">
<xsl:call-template name="nice-name" />
</xsl:template>

<xsl:template name="nice-name">
<xsl:variable name="nice-name">
<xsl:value-of select="translate(name(), ':', '_')" />
</xsl:variable>
<fo:block>
<fo:inline font-weight="bold">
<xsl:value-of select="document('element_names.xsl')//xsl:variable[@name=$nice-name]" />
</fo:inline>
<xsl:text>: </xsl:text>
<fo:inline>
<xsl:value-of select="." />
</fo:inline>
</fo:block>
</xsl:template>

I effectively call the nice-name template for a large number of tags, as specified by the massive list of match tags. Is there a better, or more efficient way to do this?

Postnext
Elias HuterSubject: Simplify This... Am I Missing Something?
Author: Elias Huter
Date: 14 May 2007 08:36 AM
If you have no existant list of the tag=nice_name codelist you will always have to maintain this information manually somehow. If you could generate this information there might be more comfortable ways of solving your problem.

If you have to maintain it manually:
The only thing I could imagine would be to maintain the information in a database or file and read it from there via Java Coding which is nested in your XSLT file. This would have the advantage that you can maintain your Codelists without touching the XSLT file itself. But as this is certainly more work it's not really a better way but more a question of your personal preference.

Postnext
Max MandersSubject: Simplify This... Am I Missing Something?
Author: Max Manders
Date: 14 May 2007 08:50 AM
I currently maintain the list of tag=nice-name mappings in a separate xml file that contains lines like this for example:
<xsl:variable name="ns_tagname">Tag Name</xsl:variable>

I then retrieve that nice-name using the nice-name template, which translates the name of the current node, by replacing the colon between namespace and tagname with an underscore. This new name is then looked up in the external variable file where the variable name attribute matches the translated name. The text value of this variable is then substituted into the original document.

What do you mean by Java Code? I didn't know you could embedd Java into XSLT, or do you mean write a Java class that does the transform instead of XSLT? Could you elaborate on this approach, and would it be any more efficient than the approach describe in the paragraph above?

Posttop
Elias HuterSubject: Simplify This... Am I Missing Something?
Author: Elias Huter
Date: 15 May 2007 02:49 AM
I'm not sure if every parser can do it, but some certainly do. You can call static classes from within your xslt mapping and even work with objects.

We use this for example for:
- Getting todays date time (we use XSLT 1.0)
- Setting and Getting Variables which are stored during the mapping runtime
- Converting strings
- etc ...

In your case the only advantage would be that you wouldnt have to re-deploy your XSL files (or ZIP/JAR file with XSLs) if you write a java extension which gets the data needed from a file or database. On the other hand it might not be that performant, but I'm not sure about that. Other than that your current solution seems (for me) to fit your needs pretty good!

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.