Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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 20th, 2008, 12:52 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generating XSLT with XSLT

I want to generate XSLT with XSLT, but the problem is that then during transformation ugly attribute xmlns:xsl="" and new XSLT file is not valid.
Is it possible to generate XSLT using XSLT or it is beyond XSLT capabilities to produce valid XML if target schema is XSL?

Example input xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet version="2.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" >
    <xslt:output method="xml" version="1.0" encoding="UTF-8" indent="yes" standalone="yes"/>
    <xslt:template match="/">
        <xslt:copy>
            <xslt:copy-of select="@*"/>
            <xslt:apply-templates/>
        </xslt:copy>
    </xslt:template>
    <xslt:template name="span" match="span">
        <xsl:copy-of>
            <xslt:attribute name="select">//tr[td[1]/p='<xslt:value-of select="current()/@id" />']/td[2]/p/span</xslt:attribute>
        </xsl:copy-of>
    </xslt:template>
    <xslt:template name="span2" match="*[name()!='span']">
        <xslt:copy>
            <xslt:copy-of select="@*"/>
            <xslt:apply-templates/>
        </xslt:copy>
    </xslt:template>
</xslt:stylesheet>


Input xml:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <body>
                [list]
                    <li><span id="87"> </span></li>
                    <li><span id="92"> </span></li>
                </ul>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>



Output xsl:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <body>
                [list]
                    <li>
<xsl:copy-of xmlns:xsl="" select="//tr[td[1]/p='87']/td[2]/p/span"/>
</li>
                    <li>
<xsl:copy-of xmlns:xsl="" select="//tr[td[1]/p='92']/td[2]/p/span"/>
</li>
                </ul>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>


I tried many combinations of namespaces nothing helps.

As you do understand operating system and processor are not important (they all produce the same results).

 
Old March 20th, 2008, 04:00 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, you can generate XSLT using XSLT. There's a special feature you can use to get round your problem called xsl:namespace-alias. You'll find information about it, and an example, here:

http://www.w3.org/TR/xslt20/#element-namespace-alias

This is XSLT 2.0 but it hasn't changed very much since 1.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 25th, 2008, 01:07 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the info. I spent all day trying to solve it. I hope this will work.

 
Old April 1st, 2008, 08:17 PM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried it. It works! Excellent and simple solution. Thanks again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating a comma-delimited data in XSLT dude153 XSLT 2 November 30th, 2007 12:12 PM
Dynamically generating Javascript (XSLT in IE6) einszwei XSLT 1 June 28th, 2007 01:07 PM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
generating a table w. xslt, newbie problem themuffinman_swe XSLT 5 November 26th, 2005 01:05 PM
Generating aspx pages with xml and xslt glaseur XSLT 4 December 3rd, 2003 05:27 AM





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