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 July 3rd, 2006, 12:47 AM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default inserting element wihout template match

How would I accomplish this?

My xml file looks like this:

<a...>

<a...>

<a...>
...

I want to create an stylesheet that do some stuff within the a element's attributes but wihtouht creating a new element everytime it finds the a element, right now i have

<xsl:template match=a>
<xsl:element name="x">
<xs:apply templates/>
</>

So every time it find the element a creates x, is there any way to just create the element x just once then apply the tempates?.

thanks.

 
Old July 3rd, 2006, 08:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You say: My xml file looks like this:

<a...>

<a...>

<a...>
...

But it can't do, that wouldn't be well formed. There must be an outer element, let's call it B. If you want to create the element x just once, then create it in the template rule with match="B".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 3rd, 2006, 12:46 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are right. I didn't explain myself correctly. my xml looks like this:

<a>
 <b/>
 <c/>
 <c/>
 <c/>
 <c/>
</a>

Then my xsl:

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

then

<xsl:tempate match=c>
<xsl:element name=x>
<xsl:apply-templates/>
....

So I still cant see a way to create the element x just once.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Param in template match=" " iceandrews XSLT 2 May 7th, 2008 07:37 AM
value-of inside template match RoeZ XSLT 5 April 17th, 2008 12:09 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Match element based on attribute of child? transom XSLT 1 September 11th, 2005 03:26 PM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM





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