Delia Lei
Delia Lei

Reputation: 15

How to get the element of the variable in the xslt

I have this transcript.xml imported as I have another source xml for the xsl

transcript.xml

<?xml version="1.0" encoding="UTF-8"?>
<t:transcript
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:t='http://namespace.profile.com/ns/transcript'
    xsi:schemaLocation='http://namespace.profile.com/ns/transcript transcript.xsd'>
    <t:studentName>Eva</t:studentName>
    <t:courses>
        <t:course>
            <t:code>IK2210</t:code>        
            <t:credits>3</t:credits>
            <t:grade>A</t:grade>
        </t:course>
        <t:course>
            <t:code>IB2210</t:code>
            <t:credits>3</t:credits>
            <t:grade>A</t:grade>
        </t:course>
        <t:course>
            <t:code>IB2210</t:code>
            <t:credits>1</t:credits>
            <t:grade>C</t:grade>
        </t:course>
        <t:course>
            <t:code>ID1234</t:code>
            <t:credits>2</t:credits>
            <t:grade>B</t:grade>
        </t:course>
    </t:courses>
</t:transcript>

and here's part of the code of the xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:t='http://namespace.profile.com/ns/transcript'>
<xsl:output method="xml" />
<xsl:variable name="transcript" select="document('transcript.xml')/transcript"/> 

neither of below work

<xsl:value-of select="$transcript/t:courses/t:course"/>
<xsl:value-of select="$transcript/courses/course"/>
<xsl:value-of select="$transcript/courses/t:course"/>

How should I call the element of the variable? Thanks!

Upvotes: 1

Views: 117

Answers (1)

Thomas W
Thomas W

Reputation: 15371

You forgot to add the namespace prefix to your variable $transcript:

<xsl:variable name="transcript" select="document('transcript.xml')/t:transcript"/> 

Upvotes: 2

Related Questions