Hi all,
I've been trying to use a lookup table in order to find a text prompt according to the key(@name) that is retrieved from the source xml.
Here follows snippets of my xml and xsl.
It all looks to be correct, but it's not displaying the prompt text...
I would appreciate a fresh pair of eyes on this.

Lookup XML - prompts.xml:

<prompts>
<prompt>
<key>rentity_branch</key>
<value>Branch</value>
</prompt>
<prompt>
<key>reason</key>
<value>Reason</value>
</prompt>
<prompt>
<key>action</key>
<value>Action taken</value>
</prompt>
...
</prompts>

Source XML to be transformed to HTML:

<element>
<element name="rentity_branch" type="string" mandatory="false" uid="report:rentity_branch"/>
        <element name="submission_code" type="string" enum="true" mandatory="true" uid="report:submission_code"/>
        <element name="report_code" type="string" enum="true" mandatory="true" uid="report:report_code"/>
....
</element>

XSL: in this snippet i'm trying to get the rentity_branch element to display a prompt text:

<xsl:key name="promptLookup" match="prompt" use="key"/>
<xsl:variable name="promptsElt" select="document('prompts.xml')/prompts"/>

<xsl:template match="*[@name='rentity_branch']">
        <span class="lineval">

            <xsl:apply-templates select="$promptsElt">
                <xsl:with-param name="curr-element" select="./@name"/>
            </xsl:apply-templates>           
            <xsl:text> : </xsl:text>
            <input>
                <xsl:attribute name="type">text</xsl:attribute>
                <xsl:attribute name="class">box</xsl:attribute>
                <xsl:attribute name="id">
                    <xsl:value-of select="@uid"/>
                </xsl:attribute>
                <xsl:attribute name="name">
                    <xsl:value-of select="@uid"/>
                </xsl:attribute>
                <xsl:attribute name="value">
                    <xsl:value-of select="current()"/>
                </xsl:attribute>
            </input>
        </span>

</xsl:template>

<xsl:template match="prompts">
   <xsl:param name="curr-element"/>
   <xsl:value-of select="key('promptLookup', $curr-element)/value"/>
</xsl:template>

Well, I don't really have an answer. I took your documents and ran them myself in Stylus Studio, using the Saxon Processor 9.X (XSLT 2.0) and everything worked perfectly fine. I also ran it command line using an older version of Saxon and it worked as well. Obviously this is just a snippet of the code that being ran, so the problem has to be somewhere else? Is it possible that this set of templates isn't being invoked? Other than that it could be a processor problem.

Have you verified that your "promptsElt" variable is being loaded correctly and that the "prompts.xml" document is being stored? If that variable is empty, you'll just get an empty result when you call the key(). Do a copy-of of your variable somewhere so you can see it's stored properly.

Below is how I modified your documents and used them. "input.xml" was the input to the transformation, "prompts.xml" was obviosuly the lookup table, and "output.xml" was my result document.

Input.xml

<element>
	<element name="rentity_branch" type="string" mandatory="false" uid="report:rentity_branch"/>
	<element name="submission_code" type="string" enum="true" mandatory="true" uid="report:submission_code"/>
	<element name="report_code" type="string" enum="true" mandatory="true" uid="report:report_code"/>
</element>

Transformation

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:key name="promptLookup" match="prompt" use="key"/>
	<xsl:variable name="promptsElt" select="document('prompts.xml')/prompts"/>

	<xsl:template match="*[@name='rentity_branch']">
		<span class="lineval">
			<xsl:apply-templates select="$promptsElt">
				<xsl:with-param name="curr-element" select="./@name"/>
			</xsl:apply-templates>
		</span>
	</xsl:template>

	<xsl:template match="prompts">
		<xsl:param name="curr-element"/>
		<xsl:value-of select="key('promptLookup', $curr-element)/value"/>
	</xsl:template>
</xsl:stylesheet>

Output.xml

<span class="lineval">Branch</span>

Thank you very much iceandrews for taking the time to look at this. I'll troubleshoot some more and post back once i know what was the trouble. Good to know the code is working though.

Let me know what you find; I'm curious now :)

Yes it is as you said, the promptselt variable hasn't been loaded due to - file permissions (blush). I'm doing this on a linux platform, too much time spent on certain other platforms lately..

Har har :) I've done it 100 times. I've gotten used to the first time writing my program now to do something like the following when I bring in external sources. Glad it was something simple.

<xsl:template match="/" >
    <xsl:copy-of select="$mySource" />
</xsl:template>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.