Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT variable not recognized

I've worked with XSLT variables before, but for some reason, I can not get the stylesheet to see an assigned variable. When I copy sample code it seems to work, so it has to be something I'm doing wrong. Below is the code.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
    <xsl:template match="/JDF">
    <xsl:variable name="customer" 
        select="/JDF/ResourcePool[1]/CustomerInfo[1]/@CustomerID"/>
            <job>
                <jobInfo>$customer</jobInfo>
            </job>
    </xsl:template>
</xsl:stylesheet>

When I run the above the result is this.

<?xml version="1.0" encoding="UTF-8"?>
<job>
   <jobInfo>$customer</jobInfo>
</job>
like image 649
ItalianDadx2 Avatar asked Sep 13 '25 23:09

ItalianDadx2


1 Answers

XSLT 1.0, 2.0

Change

<jobInfo>$customer</jobInfo>

to

<jobInfo>
  <xsl:value-of select="$customer"/>
</jobInfo>

XSLT 3.0+

If text value templates are enabled (using, for example xsl:stylesheet/@expand-text="yes"), then you could use:

<jobInfo>{$customer}</jobInfo>
like image 137
kjhughes Avatar answered Sep 15 '25 12:09

kjhughes