Not able to access variable from one XSLT into another

Hi,
Myinput xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
      <book>
            <name>VB</name>
            <title>VB6</title>
            <author>P</author>
      </book>
</books>

Myfirst xsl a.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:import href="b.xsl" />
      
      <xsl:output method="html" />
      
      <xsl:template match="/">
            <xsl:apply-templates select="*" />
      </xsl:template>
      
      <xsl:template match="books">
            <xsl:apply-templates select="book" />
      </xsl:template>
      
      <xsl:template match="book">
            <xsl:value-of select="Name" /> : <xsl:value-of select="name" /><br />
            <xsl:value-of select="Title" /> : <xsl:value-of select="title" /><br />
            <xsl:value-of select="Author" /> : <xsl:value-of select="author" /><br />
      </xsl:template>
      
</xsl:stylesheet>

My imported xsl b.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:variable name="Name"><xsl:text>Name</xsl:text></xsl:variable>
      <xsl:variable name="Title"><xsl:text>Title</xsl:text></xsl:variable>
      <xsl:variable name="Author"><xsl:text>Author</xsl:text></xsl:variable>
</xsl:stylesheet>

Output
: VB
: VB6
: P

I am not getting the value of the variables in my main xsl.

Regards,G.
LVL 4
gcmachelAsked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
should be
<xsl:value-of select="$Name" />

sorry
0
 
Geert BormansInformation ArchitectCommented:
<xsl:value-of select="name" />
accesses the name element in the current context
if you need to acess a variable, you need to prepend a "$"

<xsl:value-of select="$name" />
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.