• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Declaring and using a collection in XSLT

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm quite new to writing XSL. I was wondering whether it is possible to declare a variable that is a collection, e.g. something similar to a List or Map in the Java programming language.

A bit about what I want to do. I would like a collection that holds all the /order/method/description values. For each order, I check the collection. If the description does not exist in the collection, I add the description in the collection and perform some action. If the description does exist in the collection, I ignore it and move to the next order.



Is it possible to do this in XSL? All the variable declarations store a string value or a numeric value, can XSL support more complex variables? If no, is there an alternative?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One other thing you didn't know about XSLT is going to mess up that plan, no matter how you decide to store the data: once you assign a value to an xsl:variable, you subsequently can't change it. So you'll need to go back to the drawing board and design a completely different solution to your original problem.

Perhaps it would be better to just post your original problem? If you have a solution to a problem but don't know how to implement it at all, it's generally better to ask about the problem and not about the solution.

Edit: for example, if your problem is actually

I would like a collection that holds all the /order/method/description values

then just write an XPath expression which returns that directly. Like "//order/method/description".
 
Aaron John
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:One other thing you didn't know about XSLT is going to mess up that plan, no matter how you decide to store the data: once you assign a value to an xsl:variable, you subsequently can't change it. So you'll need to go back to the drawing board and design a completely different solution to your original problem.

Perhaps it would be better to just post your original problem? If you have a solution to a problem but don't know how to implement it at all, it's generally better to ask about the problem and not about the solution.

Edit: for example, if your problem is actually

I would like a collection that holds all the /order/method/description values

then just write an XPath expression which returns that directly. Like "//order/method/description".



Is there a special syntax for the double forward slash in xsl? For example, the use of "//"
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aaron John wrote:Is there a special syntax for the double forward slash in xsl? For example, the use of "//"



I don't understand the question. That is syntax.
 
Aaron John
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Aaron John wrote:Is there a special syntax for the double forward slash in xsl? For example, the use of "//"



I don't understand the question. That is syntax.



Oops, I didn't word the question properly. What I meant was - how is specifying a double slash different to specifying a single slash? I understand that specifying a single slash will point to the root element in the xml document, specifying an absolute path.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, no, you understand wrong. If you start an XPath expression with a single slash, that starts looking at the children of the context node, not the root of the document. If you start it with a double slash, that starts looking at all descendants of the context node.

But that's an excessively simple question to ask on a web forum, I think. You should really look for a tutorial about XPath; you are going to make very slow progress if you have to ask about every little thing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic