Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2010, 09:45 AM
Authorized User
 
Join Date: Jan 2010
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Default Processing code from other xml-file

Hello everybody,

I am looking for some hours for a solution. Should be very simple, but I can't find any hint. (Background: I am trying to build a DUL to HTML Transformation for diffxml. Maybe this is already done or anyone has a better idea to show xmldiffs...)

Problem: There is some pice of XSLT-code in one XML-file ('instructions.xml'), a source-file ('in.xml'), and the XSLT-Transformation ('test.xsl') working on the source-file. The Transformation should read instructions and use this as instructions for the transformation of in.xml. Instead I only can get the processor to read the instructions as text but not as instructions. (Maybe the code can better to be understood, than my English)

in.xml
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
	<node name="blabla"/>
</root>
data.xml
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
	<node name="blabla"/>
</root>
instructions.xml
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
	<inst code="//node/@name"/>
</root>
test.xsl
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1" />

<xsl:template match="/">
	<xsl:for-each select="collection('./?select=instructions.xml')/root/inst">
		<xsl:variable name="code"><xsl:value-of select="@code" /></xsl:variable>
			<xsl:value-of select="$code"/>
	</xsl:for-each>
	
	<xsl:value-of select="//node/@name" />
</xsl:template>

</xsl:stylesheet>
Any hints are really apreciated!

Best regards

Christian
 
Old March 2nd, 2010, 09:51 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you use Saxon 9 then you might want to look into using an extension function like http://www.saxonica.com/documentatio.../evaluate.html
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 2nd, 2010, 11:46 AM
Authorized User
 
Join Date: Jan 2010
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank You for that answer.

Did I get that right?

1. There is no way in XSLT to build dynamic code.
2. I have to pay to use this function in saxon (saxon pe).

What is about merging the two files to one "executable" and use this?

Regards Christian
 
Old March 2nd, 2010, 11:57 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Pure XSLT does not have any "eval" functionality to eval a string representing an XPath expression or even an XSLT stylesheet or template.

I pointed you to the Saxon 9.1 documentation of that extension function. It is available in the open source basic Saxon 9.1 version.
If you want to use Saxon 9.2 then you are right, the extension function is not available in the open source version, you need a license for one of the commercial versions.

As for building an "excutable", an XSLT stylesheet is XML thus it can be the input and/or the output of an XSLT transformation. That way you would not need an extension function but you need to apply two steps of transformation, one that generates a stylesheet and a second one that applies it.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 2nd, 2010, 12:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Writing code to construct a new stylesheet and then compiling that stylesheet is certainly an alternative, if time is more plentiful than money.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 2nd, 2010, 02:56 PM
Authorized User
 
Join Date: Jan 2010
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank you very much for the answers. Time is always rare in programming: There are too many other things on the world to do... But: I have to write code that will run in a very 'unfriendly' environment. This is not up to me.

If anyone is interested in a working example, let me know. I could post it here (some 10 kB).

What would have saved me writing a lot of lines: A hint to xsl:namespace-alias. Well: I am still learning. Thank You anyway!

Best regards

Christian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Start processing a xml document from a particular node number. codehelp LINQ 1 March 18th, 2010 05:59 AM
How to call decryption code from a xml file imlalit BOOK: Beginning Cryptography with Java 1 August 10th, 2009 09:30 AM
Processing ENTITY and NOTATION lines in xml mrame XSLT 2 August 1st, 2008 01:24 PM
Processing MS Dynamics XML Envelope Neal XSLT 2 May 22nd, 2008 05:57 AM
Need help on Processing two xml and updating one a sayanand XSLT 7 October 12th, 2007 05:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.