[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Apply-templates - how to omit top level element ta

Subject: RE: Apply-templates - how to omit top level element tags?
From: "Mike Schinkel" <mikes@xxxxxxxxx>
Date: Thu, 8 Sep 2005 16:32:23 -0400
xslt select top
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@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE:  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>
==========================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.