[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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.
0
gcmachel
Asked:
gcmachel
  • 2
1 Solution
 
Geert BormansCommented:
<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
 
Geert BormansCommented:
should be
<xsl:value-of select="$Name" />

sorry
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now