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 22nd, 2005, 02:19 PM
Authorized User
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding elements in XSLT 1.0

For my purposes, i am limited to only using Xalan, which is a XSlT 1.0 processor. My question is there a way of numbering a specific element ,say <a>, that is a child of a given node, <b> and give it its own number.

So this could be a possible input:
<b>
  <a>
  <a>
  <a>
  <c>
  <d>
  <a>
  <a>
  <c>
  <a>
</b>


And this would be my desired output:
<b>
  <x num="1">
  <x num="2">
  <x num="3">
  <x num="4">
  <x num="5">
  <x num="6">
</b>

Thanks in advance to anyone that can help out!!

 
Old July 22nd, 2005, 02:34 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:template match="a">
  <x><xsl:number/></x>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 22nd, 2005, 02:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry,

 <xsl:template match="a">
  <x>
    <xsl:attribute name="num"><xsl:number/></xsl:attribute>
  </x>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 25th, 2005, 09:41 AM
Authorized User
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It worked perfectly! Thank you very much!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding nested elements XSLT 1? Budbertzerofluff XSLT 2 November 15th, 2008 02:45 PM
Adding Additional Namespace and Prefixing Elements hangon XSLT 6 November 5th, 2007 09:29 PM
Adding elements from an XML to XSL. AjayLuthria XSLT 1 May 1st, 2007 12:12 PM
Grouping Elements using XSLT mathuranuj XSLT 2 June 21st, 2005 02:56 AM
adding option elements dynamically to a select richard.york Javascript 4 December 5th, 2003 04:57 AM





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