Basic XSLT/XSLTC question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justine Hlista

    #1

    Basic XSLT/XSLTC question

    I'm using xalan-j_2_6_0 and trying to get an example from Michael
    Kay's book to work:

    <xsl:template match="/">
    <xsl:variable name="rainbow">
    <color>red</color>
    <color>blue</color>
    <color>green</color>
    </xsl:variable>

    <xsl:for-each select="$rainbo w/color">
    <xsl:value-of select="."/>
    </xsl:for-each>
    </xsl:template>

    Both XSLTC and XSLT generate errors when they encounter the XPath
    expression in the select attribute. I cannot get XSLTC or XSLT to
    accept any expression that qualifies a variable in a select statement.

    Am I trying to do something that is strictly forbidden here? Am I
    misunderstandin g what Michael Kay's example was supposed to do?

    Any help is greatly appreciated!!

    Justine
  • Dimitre Novatchev  [MVP XML]

    #2
    Re: Basic XSLT/XSLTC question

    I guess that you read the second edition of Mike's book, in which he covered
    XSLT 1.1.

    XSLT 1.1 was never developed by the W3C into a final status and is not a
    standard. The current standard of XSLT 1.0 has the concept of RTF (Result
    Tree Fragment).

    An RTF cannot be treated like a node-set in XPath -- any such attempt
    results in raising an error -- this is exactly what you described.

    In order to process an RTF as a node-set, one must use an
    implementation-defined extension function with the usual name of node-set(),
    belonging to an implementation-dependent namespace, or use the
    common:node-set() function as defined by EXSLT.

    These functions take an RTF and convert it to a regular node-set. Then their
    result is a regular tree (a node-set having just one root node) and can be
    navigated using XPath.


    Therefore, you also have to use whatever implementation-defined
    xxx:node-set() extension function is available for your XSLT processor.


    Cheers,

    Dimitre Novatchev [XML MVP],
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


    "Justine Hlista" <jblackmorehlis ta@yahoo.com> wrote in message
    news:3e4f8f98.0 403022232.534d8 206@posting.goo gle.com...[color=blue]
    > I'm using xalan-j_2_6_0 and trying to get an example from Michael
    > Kay's book to work:
    >
    > <xsl:template match="/">
    > <xsl:variable name="rainbow">
    > <color>red</color>
    > <color>blue</color>
    > <color>green</color>
    > </xsl:variable>
    >
    > <xsl:for-each select="$rainbo w/color">
    > <xsl:value-of select="."/>
    > </xsl:for-each>
    > </xsl:template>
    >
    > Both XSLTC and XSLT generate errors when they encounter the XPath
    > expression in the select attribute. I cannot get XSLTC or XSLT to
    > accept any expression that qualifies a variable in a select statement.
    >
    > Am I trying to do something that is strictly forbidden here? Am I
    > misunderstandin g what Michael Kay's example was supposed to do?
    >
    > Any help is greatly appreciated!!
    >
    > Justine[/color]


    Comment

    • Philippe Poulard

      #3
      Re: Basic XSLT/XSLTC question

      Hi,

      It is also possible to store "XML constants" inside your stylesheet and
      refer to them with the document() function, that will be adressable with
      XPath (no extension required) :

      <xsl:styleshe et ...
      xmlns:xsl="..."
      xmlns:data="... ">

      <data:structure s>
      <rainbow>
      <color>red</color>
      <color>blue</color>
      <color>green</color>
      </rainbow>
      </data:structures >

      <xsl:template match="/">
      <xsl:variable name="rainbow"
      select="documen t('')/*/data:structures/rainbow"/>
      <xsl:for-each select="$rainbo w/color">
      <xsl:value-of select="."/>
      </xsl:for-each>
      </xsl:template>

      </xsl:stylesheet>

      Dimitre Novatchev [MVP XML] wrote:[color=blue]
      > I guess that you read the second edition of Mike's book, in which he covered
      > XSLT 1.1.
      >
      > XSLT 1.1 was never developed by the W3C into a final status and is not a
      > standard. The current standard of XSLT 1.0 has the concept of RTF (Result
      > Tree Fragment).
      >
      > An RTF cannot be treated like a node-set in XPath -- any such attempt
      > results in raising an error -- this is exactly what you described.
      >
      > In order to process an RTF as a node-set, one must use an
      > implementation-defined extension function with the usual name of node-set(),
      > belonging to an implementation-dependent namespace, or use the
      > common:node-set() function as defined by EXSLT.
      >
      > These functions take an RTF and convert it to a regular node-set. Then their
      > result is a regular tree (a node-set having just one root node) and can be
      > navigated using XPath.
      >
      >
      > Therefore, you also have to use whatever implementation-defined
      > xxx:node-set() extension function is available for your XSLT processor.
      >
      >
      > Cheers,
      >
      > Dimitre Novatchev [XML MVP],
      > FXSL developer, XML Insider,
      >
      > http://fxsl.sourceforge.net/ -- the home of FXSL
      > Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
      >
      >
      > "Justine Hlista" <jblackmorehlis ta@yahoo.com> wrote in message
      > news:3e4f8f98.0 403022232.534d8 206@posting.goo gle.com...
      >[color=green]
      >>I'm using xalan-j_2_6_0 and trying to get an example from Michael
      >>Kay's book to work:
      >>
      >><xsl:templa te match="/">
      >> <xsl:variable name="rainbow">
      >> <color>red</color>
      >> <color>blue</color>
      >> <color>green</color>
      >> </xsl:variable>
      >>
      >> <xsl:for-each select="$rainbo w/color">
      >> <xsl:value-of select="."/>
      >> </xsl:for-each>
      >></xsl:template>
      >>
      >>Both XSLTC and XSLT generate errors when they encounter the XPath
      >>expression in the select attribute. I cannot get XSLTC or XSLT to
      >>accept any expression that qualifies a variable in a select statement.
      >>
      >>Am I trying to do something that is strictly forbidden here? Am I
      >>misunderstand ing what Michael Kay's example was supposed to do?
      >>
      >>Any help is greatly appreciated!!
      >>
      >>Justine[/color]
      >
      >
      >[/color]


      --
      Cordialement,

      ///
      (. .)
      -----ooO--(_)--Ooo-----
      | Philippe Poulard |
      -----------------------

      Comment

      • Dimitre Novatchev  [MVP XML]

        #4
        Re: Basic XSLT/XSLTC question


        "Philippe Poulard" <Philippe.Poula rdNO@SPAMsophia .inria.fr> wrote in message
        news:c26omu$7f6 $1@news-sop.inria.fr...[color=blue]
        > Hi,
        >
        > It is also possible to store "XML constants" inside your stylesheet and
        > refer to them with the document() function, that will be adressable with
        > XPath (no extension required) :[/color]

        Yes, and this is a really valuable technique for creating data structures to
        be used by the XSLT application.

        The example given by the OP can be solved completely that way.

        What cannot be done in this way is to access dynamically created nodes.


        Cheers,

        Dimitre Novatchev [XML MVP],
        FXSL developer, XML Insider,

        http://fxsl.sourceforge.net/ -- the home of FXSL
        Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


        Comment

        Working...