XSLT2.0 temporary nodeset as parameter

Discussion in 'XML' started by RolfK, Dec 17, 2007.

  1. RolfK

    RolfK Guest

    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 -->
    <!-- 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"/>
    </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 ##########################
    RolfK, Dec 17, 2007
    #1
    1. Advertising

  2. RolfK

    Pavel Lepin Guest

    RolfK <> wrote in
    <>:
    > 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.
    Pavel Lepin, Dec 17, 2007
    #2
    1. Advertising

  3. RolfK

    RolfK Guest

    On 17 Dez., 08:55, Pavel Lepin <> wrote:
    > RolfK <> wrote in
    > <>:
    >
    >
    >
    >
    >
    > > 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
    RolfK, Dec 18, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Philips
    Replies:
    3
    Views:
    369
    John Keyes
    Sep 23, 2004
  2. Ken Philips
    Replies:
    1
    Views:
    348
    Tjerk Wolterink
    Sep 22, 2004
  3. Harry Zoroc
    Replies:
    1
    Views:
    748
    Boris Poehlmann
    Sep 23, 2004
  4. Bryan Galvin
    Replies:
    2
    Views:
    429
    Bryan Galvin
    Sep 29, 2004
  5. Replies:
    0
    Views:
    594
Loading...

Share This Page