Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes XML and Related Technologies and the fly likes XSL and Enumeration Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL and Enumeration Query" Watch "XSL and Enumeration Query" New topic
Author

XSL and Enumeration Query

Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
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:







SCJP<br />SCJD
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

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

Joined: Feb 04, 2004
Posts: 288
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
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

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.
 
Consider Paul's rocket mass heater.
 
subject: XSL and Enumeration Query