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 February 22nd, 2012, 05:11 AM
Registered User
 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reference XSLT inside of another XSLT

Hello basically i am woundering if it would be possible to reference one XSLT from another.

In terms of code this is that i mean. Below is the code full code that i want to use:

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="time_generated"></xsl:param>
    <xsl:template match="/getDeliveryPdfResponse">
        <response>
            <header>
                <xsl:choose>
                    <xsl:when test="rcode = 0">
                        <status>200</status>
                    </xsl:when>
                    <xsl:when test="rcode = 1">
                        <status>201</status>
                    </xsl:when>
                    <xsl:when test="rcode = 2">
                        <status>202</status>
                    </xsl:when>
                    <xsl:when test="rcode = 3">
                        <status>203</status>
                    </xsl:when>
                    <xsl:when test="rcode = 4">
                        <status>204</status>
                    </xsl:when>
                    <xsl:when test="rcode = 5">
                        <status>205</status>
                    </xsl:when>
                    <xsl:when test="rcode = 6">
                        <status>206</status>
                    </xsl:when>
                    <xsl:when test="rcode = 7">
                        <status>207</status>
                    </xsl:when>
                    <xsl:when test="rcode = 8">
                        <status>208</status>
                    </xsl:when>
                    <xsl:when test="rcode = 9">
                        <status>209</status>
                    </xsl:when>
                </xsl:choose>
                <message_detail><xsl:value-of select="rmessage"></xsl:value-of></message_detail>
                <apikey_detail>
                    <class/>
                    <rate-limit-remaining/>
                    <rate-limit-reset/>
                </apikey_detail>
            </header>
            <data>
                <xsl:copy-of select="payload/node()"/>
            </data>
        </response>	
    </xsl:template>
</xsl:stylesheet>
However this chunk

Code:
                <xsl:choose>
                    <xsl:when test="rcode = 0">
                        <status>200</status>
                    </xsl:when>
                    <xsl:when test="rcode = 1">
                        <status>201</status>
                    </xsl:when>
                    <xsl:when test="rcode = 2">
                        <status>202</status>
                    </xsl:when>
                    <xsl:when test="rcode = 3">
                        <status>203</status>
                    </xsl:when>
                    <xsl:when test="rcode = 4">
                        <status>204</status>
                    </xsl:when>
                    <xsl:when test="rcode = 5">
                        <status>205</status>
                    </xsl:when>
                    <xsl:when test="rcode = 6">
                        <status>206</status>
                    </xsl:when>
                    <xsl:when test="rcode = 7">
                        <status>207</status>
                    </xsl:when>
                    <xsl:when test="rcode = 8">
                        <status>208</status>
                    </xsl:when>
                    <xsl:when test="rcode = 9">
                        <status>209</status>
                    </xsl:when>
                </xsl:choose>
I want to source from another external XSLT so that i can use it in many different XSLT and therefore if i ever want to update a status code i only have to change one XSLT not the 100's that we have.

Is this possible?

Many Thanks
 
Old February 22nd, 2012, 05:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sure, you can use xsl:include or xsl:import to incorporate code from one stylesheet module into another.

Mind you, I would be strongly temped to replace your xsl:choose with

Code:
<status><xsl:value-of select="rcode + 200"/></status>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 22nd, 2012, 06:14 AM
Registered User
 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your reply. I have been looking into it a little further and correct me if i am wrong. When you do an include it caches the referenced XSLT. Does this happen for an import to? As this would then cause a huge issue when altering the imported XSLT?!

In addition thank you for the idea to use:

Code:
<status><xsl:value-of select="rcode + 200"/></status>
However wouldnt the

Code:
"rcode + 200"
Part mean that it would then output both the rcode and 200. However i only want to see the 200

many thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET COntrols inside XSLT sani723 XSLT 8 March 22nd, 2007 07:15 AM
ASP.Net Web Server Controls inside XSLT russmack XSLT 2 December 14th, 2006 10:02 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
Problem with JScript inside XSLT chrisybhoy XSLT 6 September 17th, 2003 07:13 AM





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