XSLT with input parameter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bbembi_de@lycos.de

    XSLT with input parameter

    Hello everyone,

    is it possible to give a transformation a input parameter?
    I want to use this parameter as a variable in my transformation.

    thanks.

    bye bembi
  • Martin Honnen

    #2
    Re: XSLT with input parameter

    bbembi_de@lycos .de wrote:
    is it possible to give a transformation a input parameter?
    I want to use this parameter as a variable in my transformation.
    Yes, that is possible, you define a top-level xsl:param element with the
    name of the parameter and then you use the API of your XSLT processor to
    set that parameter before running the transformation.

    <xsl:styleshe et
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:param name="p1"/>

    <xsl:template match="/">
    <xsl:value-of select="$p1"/>
    </xsl:template>
    </xsl:stylesheet>





    --

    Martin Honnen

    Comment

    • bbembi_de@lycos.de

      #3
      Re: XSLT with input parameter

      Thank you very much.

      bembi


      On 16 Mai, 17:04, Martin Honnen <mahotr...@yaho o.dewrote:
      bbembi...@lycos .de wrote:
      is it possible to give a transformation a input parameter?
      I want to use this parameter as a variable in my transformation.
      >
      Yes, that is possible, you define a top-level xsl:param element with the
      name of the parameter and then you use the API of your XSLT processor to
      set that parameter before running the transformation.
      >
      <xsl:styleshe et
      xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
      version="1.0">
      >
      <xsl:param name="p1"/>
      >
      <xsl:template match="/">
      <xsl:value-of select="$p1"/>
      </xsl:template>
      </xsl:stylesheet>
      >
      --
      >
      Martin Honnen
      http://JavaScript.FAQTs.com/

      Comment

      • bbembi_de@lycos.de

        #4
        Re: XSLT with input parameter

        Hello again,

        is it possible to give the XSLT a variable number of parameter and use
        it in a array?


        Thanks.
        bye bembi



        On 18 Mai, 18:28, "bbembi...@lyco s.de" <bbembi...@lyco s.dewrote:
        Thank you very much.
        >
        bembi
        >
        On 16 Mai, 17:04, Martin Honnen <mahotr...@yaho o.dewrote:
        >
        >
        >
        bbembi...@lycos .de wrote:
        is it possible to give a transformation a inputparameter?
        I want to use thisparameteras a variable in my transformation.
        >
        Yes, that is possible, you define a top-level xsl:param element with the
        name of theparameterand then you use the API of yourXSLTprocess or to
        set thatparameterbe fore running the transformation.
        >
           <xsl:styleshe et
             xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
             version="1.0">
        >
             <xsl:param name="p1"/>
        >
             <xsl:template match="/">
               <xsl:value-of select="$p1"/>
             </xsl:template>
           </xsl:stylesheet>
        >
        --
        >
                Martin Honnen
               http://JavaScript.FAQTs.com/- Zitierten Text ausblenden -
        >
        - Zitierten Text anzeigen -

        Comment

        • Joseph J. Kesselman

          #5
          Re: XSLT with input parameter

          bbembi_de@lycos .de wrote:
          is it possible to give the XSLT a variable number of parameter and use
          it in a array?
          For the first: Parameters can have default values. Or you could pass a
          parameter which your stylesheet then parses data out of.

          XSLT has no concept of "arrays". Some processors will let you pass in
          non-XSLT objects but the only thing you can do with them, really, is to
          pass them along to extension functions.

          You might get more useful answers if you told us what you're trying to
          do rather than asking whether a particular approach is possible.

          Comment

          • Martin Honnen

            #6
            Re: XSLT with input parameter

            bbembi_de@lycos .de wrote:
            is it possible to give the XSLT a variable number of parameter and use
            it in a array?
            Depending on the XSLT processor you use it might be possible to pass in
            an XML document exposed as a node-set to XSLT/XPath. For instance MSXML
            allows you to build and pass in an XML DOM document.
            XslCompiledTran sform allows that too. See

            for the .NET types you can pass in and how the translate into XPath/XSLT
            types.


            --

            Martin Honnen

            Comment

            • bbembi_de@lycos.de

              #7
              Re: XSLT with input parameter

              Thanks for the answers so far.

              To give you the whole story:
              I want to do this: I have a XML like:
              <root>
              <entry type='a' />
              <entry type='b' />
              <entry type='c' />
              </root>

              Now I want to pass a variable number of types. All these will be
              exported:
              Example:
              parameters: a, b
              Output:
              <root>
              <entry type='a' />
              <entry type='b' />
              </root>

              bye bembi



              On 21 Mai, 15:47, "Joseph J. Kesselman" <keshlam-nos...@comcast. net>
              wrote:
              bbembi...@lycos .de wrote:
              is it possible to give theXSLTa variable number ofparameterand use
              it in a array?
              >
              For the first: Parameters can have default values. Or you could pass aparameterwhich your stylesheet then parses data out of.
              >
              XSLThas no concept of "arrays". Some processors will let you pass in
              non-XSLTobjects but the only thing you can do with them, really, is to
              pass them along to extension functions.
              >
              You might get more useful answers if you told us what you're trying to
              do rather than asking whether a particular approach is possible.

              Comment

              • Joseph J. Kesselman

                #8
                Re: XSLT with input parameter

                bbembi_de@lycos .de wrote:
                parameters: a, b
                Output:
                <root>
                <entry type='a' />
                <entry type='b' />
                </root>
                I'd suggest passing a single parameter which contains a delimited string
                of the values you want to match, and writing the test to use it in that
                form... exactly as you've shown it here.

                I did a simple and sloppy version of that in part 2 of my "styling
                stylesheets" article on DeveloperWorks (http://www.ibm.com/xml).

                Comment

                • Martin Honnen

                  #9
                  Re: XSLT with input parameter

                  bbembi_de@lycos .de wrote:
                  To give you the whole story:
                  I want to do this: I have a XML like:
                  <root>
                  <entry type='a' />
                  <entry type='b' />
                  <entry type='c' />
                  </root>
                  >
                  Now I want to pass a variable number of types. All these will be
                  exported:
                  Example:
                  parameters: a, b
                  Output:
                  <root>
                  <entry type='a' />
                  <entry type='b' />
                  </root>
                  Which XSLT processor do you use?


                  --

                  Martin Honnen

                  Comment

                  • bbembi_de@lycos.de

                    #10
                    Re: XSLT with input parameter

                    I am not sure which XSLT processor will be used.
                    The transformation will be integreated in a existing system. I think
                    it is saxon 8.?

                    bye bembi


                    On 21 Mai, 18:25, Martin Honnen <mahotr...@yaho o.dewrote:
                    bbembi...@lycos .de wrote:
                    To give you the whole story:
                    I want to do this: I have a XML like:
                    <root>
                      <entry type='a' />
                      <entry type='b' />
                      <entry type='c' />
                    </root>
                    >
                    Now I want to pass a variable number of types. All these will be
                    exported:
                    Example:
                    parameters: a, b
                    Output:
                    <root>
                      <entry type='a' />
                      <entry type='b' />
                    </root>
                    >
                    WhichXSLTproces sor do you use?
                    >
                    --
                    >
                            Martin Honnen
                           http://JavaScript.FAQTs.com/- Zitierten Text ausblenden -
                    >
                    - Zitierten Text anzeigen -

                    Comment

                    • Martin Honnen

                      #11
                      Re: XSLT with input parameter

                      bbembi_de@lycos .de wrote:
                      I am not sure which XSLT processor will be used.
                      The transformation will be integreated in a existing system. I think
                      it is saxon 8.?
                      Well there are different versions of Saxon 8 supporting different
                      version of the XSLT 2.0 draft but with Saxon 8.9 or 9.0 which support
                      the final XSLT 2.0 specification you could easily use the tokenize
                      function to split up a string value passed in into a sequence of strings:

                      <xsl:styleshe et
                      xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      exclude-result-prefixes="xs"
                      version="2.0">

                      <xsl:output method="xml" indent="yes"/>

                      <xsl:param name="types" as="xs:string"/>

                      <xsl:variable name="type-list" as="xs:string* "
                      select="tokeniz e($types, ',')"/>

                      <xsl:template match="root">
                      <xsl:copy>
                      <xsl:apply-templates select="@*"/>
                      <xsl:apply-templates select="entry[@type = $type-list]"/>
                      </xsl:copy>
                      </xsl:template>

                      <xsl:template match="@* | node()">
                      <xsl:copy>
                      <xsl:apply-templates select="@* | node()"/>
                      </xsl:copy>
                      </xsl:template>

                      </xsl:stylesheet>

                      Then you could use Saxon 9 from the command line as follows:

                      java -jar saxon9.jar -s:input.xml -xsl:stylesheet. xsl types=a,b


                      --

                      Martin Honnen

                      Comment

                      Working...