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
Jon MowrySubject: Dynamic Transformations
Author: Jon Mowry
Date: 11 May 2006 07:04 AM
Originally Posted: 11 May 2006 06:46 AM
I'm trying to create an XSLT stylesheet that will convert from an input structure to an output structure, but without having prior knowledge of what those formats are. The input to the XSL transformer would contain three parts: 1) The INPUT_DOCUMENT tag contains the input format that I would like to convert. 2) The OUTPUT_FORMAT tag contains the structure that I want the INPUT_DOCUMENT to be converted to. 3) The CONVERSION tag contains individual MAPPING tags that define how the Input data should be mapped to the output structure. Here's an example:

<ROOT>
<INPUT_DOCUMENT>
<FORMAT_ONE>
<COLOR>Red</COLOR>
</FORMAT_ONE>
</INPUT_DOCUMENT>
<OUTPUT_FORMAT>
<FORMAT_TWO>
<SYMBOL/>
</FORMAT_TWO>
</OUTPUT_FORMAT>
<CONVERSION>
<MAPPING>
<INPUT>FORMAT_ONE/COLOR</INPUT>
<OUTPUT>FORMAT_TWO/SYMBOL</OUTPUT>
</MAPPING>
</CONERSION>
</ROOT>

The desired output of the stylesheet would be:

<OUTPUT_DOCUMENT>
<FORMAT_TWO>
<SYMBOL>Red</SYMBOL>
</FORMAT_TWO>
</OUTPUT_DOCUMENT>

Obviously, this would be an easy solution if I knew exactly what the input and output structures looked like, but I want to be able to take any input and any output format with a mapping of how to convert one to the other.

Any ideas would be appreciated.



At the moment, I'm stuck on using a variable to store an XPATH. Here's a code snippet:

<xsl:for-each select="ROOT/CONVERSION/MAPPING">
<xsl:variable name="source_path"><xsl:text>/ROOT/INPUT_DOCUMENT/</xsl:text><xsl:value-of select="INPUT/text()"/><xsl:text>/text()</xsl:text></xsl:variable>
<SOURCE_VALUE><xsl:value-of select=$source_path"/></SOURCE_VALUE>
</xsl:for-each>

This is just returning the value of the variable itself, and not the value of the path that the variable contains. It's outputting:

<SOURCE_VALUE>/ROOT/INPUT_DOCUMENT/FORMAT_ONE/COLOR/text()</SOURCE_VALUE>

when what I really want is:

<SOURCE_VALUE>Red</SOURCE_VALUE>

I've tried wrapping the variable name in brackets in the xsl:value-of 'select' attribute, but the transformer just complains. Is there any way to substitute the variable into the "value-of" statement FIRST, before the "value-of" gets evaluated?

Postnext
(Deleted User) Subject: Dynamic Transformations
Author: (Deleted User)
Date: 11 May 2006 08:42 AM
Hi Jon,

Unfortunately, the XSLT standard doesn't provide for such a functionality. There are extension functions available from certain XSLT processors, like Saxon (saxon:evaluate) and Xalan (xalan:eval) that you may want to try.

Regards
Srini

Postnext
(Deleted User) Subject: Dynamic Transformations
Author: (Deleted User)
Date: 11 May 2006 08:48 AM
Here is your sample with Saxon evaluate extension:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">

<xsl:template match="/">
<xsl:for-each select="ROOT/CONVERSION/MAPPING">
<xsl:variable name="source_path">
<xsl:text>/ROOT/INPUT_DOCUMENT/</xsl:text>
<xsl:value-of select="INPUT/text()"/>
<xsl:text>/text()</xsl:text>
</xsl:variable>
<SOURCE_VALUE>
<xsl:value-of select="saxon:evaluate($source_path)"/>
</SOURCE_VALUE>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards
Srini

Posttop
Jon MowrySubject: Dynamic Transformations
Author: Jon Mowry
Date: 11 May 2006 09:56 AM
Thanks for the tip! I'll look into some of the evaluation engines that you mentioned.

Cheers,
Jon

 
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.