• 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

XSL and Enumeration Query

 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys I have a question. (This is a simplified version of my real world scenario)

I have an xml source document that has a single element that can accept the numbers 1,2, or 3. The target document has a single element that can takethe values one, two or three". (Both of these are constrained by enumeration restrictions).

Is there any way in XSL that I can take the number from the source document, and map it to the position of the enumerator of the second document, in order to return the string representation. (Like you would do if it was in a programming language array).

In my real program I am mapping potenntiially hundreds of codes to status strings, so a simple xsl:choice solution is not reallly an option (The enumerators are guaranteed to be defined in the correct order so that will not be an issue).

So I end up with the following mappings:


Source Schema:


Target Schema:






 
Marshal
Posts: 28177
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
If I'm to take your italics as what's important, then I would suggest using the position() function with a suitable XPath expression to guide it.
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for the advice however what is really confusing me is I am just not sure how to load up the document schema during the xsl processing to match the number.

The Source file is



And the document I want to produce is as follows.



I know that my XSL script must load the schema, find the value position, somehow pass in the number in DigitNumber element, find that position within the anumber simpletype and then output the text string at that position.

Something like the XSL below, which is completely wrong but I am totally lost at this stage.



While this is a trivial example in real application I will be mapping code numbers to messages.

Google is not being kind to me today either.

Thanks again, Mark.



 
Paul Clapham
Marshal
Posts: 28177
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
So your question is about how to use the document() function?

From what I read in the XSLT Recommendation, the argument of the function is converted to a string, which is then treated as a URI, and the XML document at that URI is loaded and parsed. The resulting tree is returned as the value of the function.

The first thing to do, then, is to find out what string the argument of your document() function is returning. Presumably it isn't a URI, or at least not a useful one. If you're asking how to get the URI of the schema based on the value of the xsi:noNamespaceSchemaLocation attribute, then sorry, I don't know anything about XML Schema and I don't plan to learn anything about it unless circumstances force me too. I've tried to figure it out to answer earlier questions in forums and I just got led into thickets of incomprehensible specs.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic