XSLT2.0 temporary nodeset as parameter

R

RolfK

Dear ALL,

I'm new to XSLT2.0 and want to switch from XSLT1.0 to make my scripts
smaller.
My understanding of XSLT2.0 is that I can appply XPATH(2.0) on a
fragment without calling a specific node-set function. I'm using saxon
8.0.
The example has three parts the xslt, a xml called with saxon and a
xml loaded by document function. I have to process over the two xml
node sets.

Running the xslt gives me the follwoing error message:

Error at value-of on line 29 of file:/proj/URANUS/_work_kemperr/_V1.0/
_xml/TESTCASE/Stimulus20.xslt:
Required type of first operand of '/' is node(); supplied value is
xs:string
Transformation failed: Run-time errors were reported

The question is why the parameter value is treated as string ?

In case I comment out the critical line (<xsl:value-of
select="$pParams[1]/@Value" />) I get the expeted
################ result ##################
Calling Sequence LEVEL1
Vector 2BIT
Calling Sequence LEVEL2
Nested Vector 1BIT
Nested Vector 2BIT
Vector 3BIT
duecs37: saxon StimulusTest1.xml Stimulus20.xslt
Vector 1
Calling Sequence LEVEL1
Vector 2BIT
Calling Sequence LEVEL2
Nested Vector 1BIT
Nested Vector 2BIT
Vector 3BIT

################### xslt ##############################
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<!-- saxon call: saxon StimulusTest1.xml Stimulus20.xslt -->
<xsl:variable name="gfDEF" select="document('StimulusDef1.xml')/
STIMULUSDEF"/>
<xsl:variable name="cNewLine" select="'
'"/>
<!-- we call the xslt on the StimulusTest.xml -->
<xsl:template match="/">
<xsl:apply-templates select="STIMULUS/TEST/CREATE"/>
</xsl:template>

<xsl:template match="CREATE">
<xsl:param name="pParams"/>
<xsl:variable name="vSeqName" select="@Name"/>
<xsl:value-of select="@Comment"/>
<xsl:apply-templates select="BIT">
<xsl:with-param name="pParams" select="$pParams"/>
</xsl:apply-templates>
<xsl:value-of select="$cNewLine"/>
<xsl:if test="@VectorType='Sequence'">
<xsl:apply-templates select="$gfDEF/SEQS/SEQ[@Name=$vSeqName]/
CREATE">
<xsl:with-param name="pParams" select="PARAM"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="BIT">
<xsl:param name="pParams"/>
<xsl:text>BIT</xsl:text>
<xsl:value-of select="$pParams[1]/@Value" />
</xsl:template>

</xsl:stylesheet>
################## xml called wit saxon ####################
<?xml version="1.0" encoding="UTF-8"?>
<STIMULUS DefPath="StimulusDef.xml">
<TEST Name="MyTest" >
<CREATE VectorType="Vector" Comment="Vector 1"/>
<CREATE VectorType="Sequence" Name="LEVEL1" Comment="Calling
Sequence LEVEL1">
<PARAM Name="Addr" Value="'ADDR1'"/>
<PARAM Name="Write" Value="'DATA1'"/>
</CREATE>
<CREATE VectorType="Vector" Split="CSISplit" Comment="Vector 2">
<BIT Name="BIT1" Value="2"/>
</CREATE>
<CREATE VectorType="Sequence" Name="LEVEL2" Comment="Calling
Sequence LEVEL2">
<PARAM Name="Addr" Value="'ADDR2'"/>
<PARAM Name="Write" Value="'DATA2'"/>
</CREATE>
<CREATE VectorType="Vector" Comment="Vector 3">
<BIT Name="BIT1" Value="3"/>
</CREATE>
</TEST>
</STIMULUS>
######################## xml called by document function ############
<?xml version="1.0" encoding="UTF-8"?>
<STIMULUSDEF>
<SEQS>
<SEQ Name="LEVEL2" Comment="Level 2">
<CREATE VectorType="Vector" Comment="Nested Vector 1" >
<BIT Name="BIT1" Value="2.1"/>
</CREATE>
<CREATE VectorType="Vector" Comment="Nested Vector 2">
<BIT Name="BIT1" Value="2.2"/>
</CREATE>
</SEQ>
<SEQ Name="LEVEL1A" Comment="Level 1A">
<CREATE VectorType="Vector" Comment="LEVEL1A Vector 1" >
<BIT Name="BIT1" Value="1.1"/>
</CREATE>
<CREATE VectorType="Vector" Comment="LEVEL1A Vector 2" >
<BIT Name="BIT1" Value="1.2"/>
</CREATE>
</SEQ>
<SEQ Name="LEVEL1B" Comment="Level 1B">
<CREATE VectorType="Vector" Comment="LEVEL1B Vector 1" >
<BIT Name="BIT1" Value="10.1"/>
</CREATE>
<CREATE VectorType="Sequence" Name="LEVEL2" Comment="Call nested
sequence " >
<PARAM Name="Addr" Value="'ADDR3'"/>
<PARAM Name="Write" Value="'DATA3'"/>
</CREATE>
<CREATE VectorType="Vector" Comment="LEVEL1BVector 1" >
<BIT Name="BIT1" Value="10.2"/>
</CREATE>
</SEQ>
</SEQS>
</STIMULUSDEF>
############# END ##########################
 
P

Pavel Lepin

RolfK said:
Running the xslt gives me the follwoing error message:

Error at value-of on line 29 of
file:/proj/URANUS/_work_kemperr/_V1.0/
_xml/TESTCASE/Stimulus20.xslt:
Required type of first operand of '/' is node();
supplied value is
xs:string
Transformation failed: Run-time errors were reported

The question is why the parameter value is treated as
string ?

################### xslt ##############################
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">
<!-- saxon call: saxon StimulusTest1.xml Stimulus20.xslt
--> <!-- THIS IS A XSLT 2.0 SCRIPT -->
<xsl:eek:utput method="text" version="1.0" encoding="UTF-8"
indent="no"/
<xsl:variable name="gfDEF"
select="document('StimulusDef1.xml')/ STIMULUSDEF"/>
<xsl:variable name="cNewLine" select="'
'"/>
<!-- we call the xslt on the StimulusTest.xml -->
<xsl:template match="/">
<xsl:apply-templates select="STIMULUS/TEST/CREATE"/>

Invoked without xsl:with-param...
</xsl:template>

<xsl:template match="CREATE">
<xsl:param name="pParams"/>

....therefore this is uninitialized. See 9.2 in XSLT2, which
answers the question you posed above.
<xsl:variable name="vSeqName" select="@Name"/>
<xsl:value-of select="@Comment"/>
<xsl:apply-templates select="BIT">
<xsl:with-param name="pParams" select="$pParams"/>

And now you invoke the template application, passing
zero-length string as pParams parameter.
</xsl:apply-templates>
<xsl:value-of select="$cNewLine"/>
<xsl:if test="@VectorType='Sequence'">
<xsl:apply-templates
select="$gfDEF/SEQS/SEQ[@Name=$vSeqName]/ CREATE">
<xsl:with-param name="pParams" select="PARAM"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="BIT">
<xsl:param name="pParams"/>
<xsl:text>BIT</xsl:text>
<xsl:value-of select="$pParams[1]/@Value" />

And, naturally, it all breaks here, because, as Saxon told
you, / wants a nodeset as the first operand, and you're
passing a string. What else did you expect?
 
R

RolfK

<[email protected]>:




Running the xslt gives me the follwoing error message:
Error at value-of on line 29 of
file:/proj/URANUS/_work_kemperr/_V1.0/
_xml/TESTCASE/Stimulus20.xslt:
Required type of first operand of '/' is node();
supplied value is
xs:string
Transformation failed: Run-time errors were reported
The question is why the parameter value is treated as
string ?
################### xslt ##############################
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- saxon call: saxon StimulusTest1.xml Stimulus20.xslt
--> <!-- THIS IS A XSLT 2.0 SCRIPT -->
<xsl:eek:utput method="text" version="1.0" encoding="UTF-8"
indent="no"/
<xsl:variable name="gfDEF"
select="document('StimulusDef1.xml')/ STIMULUSDEF"/>
<xsl:variable name="cNewLine" select="'
'"/>
<!-- we call the xslt on the StimulusTest.xml -->
<xsl:template match="/">
<xsl:apply-templates select="STIMULUS/TEST/CREATE"/>

Invoked without xsl:with-param...
</xsl:template>
<xsl:template match="CREATE">
<xsl:param name="pParams"/>

...therefore this is uninitialized. See 9.2 in XSLT2, which
answers the question you posed above.
<xsl:variable name="vSeqName" select="@Name"/>
<xsl:value-of select="@Comment"/>
<xsl:apply-templates select="BIT">
<xsl:with-param name="pParams" select="$pParams"/>

And now you invoke the template application, passing
zero-length string as pParams parameter.
</xsl:apply-templates>
<xsl:value-of select="$cNewLine"/>
<xsl:if test="@VectorType='Sequence'">
<xsl:apply-templates
select="$gfDEF/SEQS/SEQ[@Name=$vSeqName]/ CREATE">
<xsl:with-param name="pParams" select="PARAM"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="BIT">
<xsl:param name="pParams"/>
<xsl:text>BIT</xsl:text>
<xsl:value-of select="$pParams[1]/@Value" />

And, naturally, it all breaks here, because, as Saxon told
you, / wants a nodeset as the first operand, and you're
passing a string. What else did you expect?
</xsl:template>
</xsl:stylesheet>

--
...also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Pavel , thanks a lot,
I think it gets clear now.
Saxon seems to be quite strict which is good in my understanding.
Rolf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top