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).
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.
Joined: Feb 04, 2004
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.
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.