xsl-list
[Top] [All Lists]

RE: Apply-templates - how to omit top level element tags?

2005-09-08 13:32:23
Oh, and here's the resultant HTML (I think I needed <xsl:output> to omit
the XML markup):

===[XML]==================================================
<?xml-stylesheet type="text/xsl" href="Test.xsl">
<How-To-Select xmlns:htsg="http://www.howtoselectguides.com/schema/";>
<html>
<head>
<META http-equiv="Content-Type" content="text/html">
<title>Test</title></head>
<body>
<h1><Name>A ProductName<TrademarkSymbol></TrademarkSymbol> is part of my
title<TrademarkSymbol></TrademarkSymbol></Name></h1>
<h1>A ProductName is part of my title</h1>
<h1><Name>A ProductName<TrademarkSymbol></TrademarkSymbol> is part of my
title<TrademarkSymbol></TrademarkSymbol></Name></h1>
<h1>A ProductName<TrademarkSymbol></TrademarkSymbol> is part of my
title<TrademarkSymbol></TrademarkSymbol></h1>
This is some more text just for show.
</body>
</html></How-To-Select>
========================================================== 

-----Original Message-----
From: Mike Schinkel 
Sent: Thursday, September 08, 2005 4:28 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: RE: [xsl] Apply-templates - how to omit top level element tags?

If the problem isn't yet solved, could we trouble you to repost a
demonstration?

As a former programming instructor and author of training materials and
a book on programming, I generally understand how to present info in
detail, and I thought I had.  But obviously not, so here's a complete
example (for posterity only, because I've solved the problem as you'll
see in comments):

===[XML]==================================================
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Test.xsl"?> <How-To-Select
xmlns:htsg="http://www.howtoselectguides.com/schema/";>
        <Guide>
                <Name>A ProductName<TrademarkSymbol/> is part of my
title<TrademarkSymbol/></Name>
                <Sections>
                        <Section>Section 1</Section>
                        <Section>Section 2</Section>
                        <Section>Section 3</Section>
                </Sections>
        </Guide>
</How-To-Select>

===[XSL]==================================================
<?xml version="1.0" encoding="utf-8" standalone="no"?> <xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="html"/>

        <xsl:variable name="trademark-symbol">&#8482;</xsl:variable>
        
        <xsl:template match="@*|node()">
                <xsl:copy>
                        <xsl:apply-templates select="@*|node()"/>
                </xsl:copy>
        </xsl:template>
        
        <xsl:template match="Trademark">
                <xsl:value-of select="$trademark-symbol"/>
        </xsl:template>
        
        <xsl:template match="/How-To-Select/Guide">
                <html>
                        <head><title>Test</title></head>
                        <body>
                                <h1>
                                        <!-- THIS DIDN'T WORK - INCLUDE
<Name/> TAGS -->
                                        <xsl:apply-templates
select="Name"/>
                                </h1>
                                <h1>
                                        <!-- THIS DIDN'T WORK - OMITS
Trademark Symbol -->
                                        <xsl:value-of select="Name"/>
                                </h1>
                                <h1>
                                        <!-- THIS DIDN'T WORK - INCLUDES
<Name/>, <Trademark/>, DOES NOT EXPAND <Trademark/> -->
                                        <xsl:copy-of select="Name"/>
                                </h1>
                                <h1>
                                        <!-- THIS IS WHAT I NEEDED -->
                                        <xsl:apply-templates
select="Name/node()"/>
                                </h1>
                                This is some more text just for show.
                        </body>
                </html>
        </xsl:template>

</xsl:stylesheet>
==========================================================

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--