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 October 11th, 2007, 08:49 AM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default Working with array-type elements

I have an array (if you can call it that in XSLT) of elements like:

ownedMember(100)

and I want to do two things:

1) How do I traverse them individually (i.e. in a loop)?

2) How do I get to individual attributes within any given array element?


Thanks


 
Old October 11th, 2007, 09:07 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't quite understand the ownedMember(100) syntax but if you have XML such as:
Code:
<data>
  <ownedMember attribute="value"/>
  <ownedMember attribute="value"/>

</data>
Then you have an xsl:template with a match attribute of ownedMember and then you call:
Code:
<xsl:apply-templates select="/*/ownedMember"/>
Then you can access the attributes as so:
Code:
<xsl:template match="ownedMember">
  <xsl:value-of select="@attribute"/>
</xsl:template>

--

Joe (Microsoft MVP - XML)
 
Old October 11th, 2007, 09:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You don't have an array in XSLT (and you can't call it that, because it will only confuse people). In XSLT 2.0 you can have a sequence of elements, in XSLT 1.0 you can have a node-set. In either case you can index into the collection using predicates, for example $x[100], and you can iterate over the collection using <xsl:for-each>

I'm a little surprised at such a basic question, perhaps you meant something else?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
Accessing elements of an Array object abdulqadirpk VB How-To 1 April 2nd, 2007 11:13 AM
unordered elements in complex type mandabear XML 0 September 3rd, 2004 11:08 AM
Add elements to array TSEROOGY Javascript 5 February 22nd, 2004 03:16 PM





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