Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. xsl:variable

xsl:variable

Scheduled Pinned Locked Moved XML / XSL
xmlcsharptutorialquestion
6 Posts 3 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    Does anyone know how to call a stylesheet and pass in a variable value ? I'm doing some docs using the XML generated by .NET and I want to pass in the node to look up for each page that documents one function, so I can pull out the parameters, etc. I hope to do this with one XSL, but at the moment it's something like <xsl;for-each select="[contains[@name, "M:XMLObject:functionname"]/> This works, but I'm not sure how to change 'functionname' dynamically, except by passing the xsl through another xsl sheet, and I don't want to do that, I want to set the value with a variable, and set the variable as I call the sheet. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

    Richard DeemingR S 2 Replies Last reply
    0
    • C Christian Graus

      Does anyone know how to call a stylesheet and pass in a variable value ? I'm doing some docs using the XML generated by .NET and I want to pass in the node to look up for each page that documents one function, so I can pull out the parameters, etc. I hope to do this with one XSL, but at the moment it's something like <xsl;for-each select="[contains[@name, "M:XMLObject:functionname"]/> This works, but I'm not sure how to change 'functionname' dynamically, except by passing the xsl through another xsl sheet, and I don't want to do that, I want to set the value with a variable, and set the variable as I call the sheet. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      I think what you're after is the xsl:param, combined with an xsl:call-tempalte or xsl:apply-templates call. For example, I use the following template to remove duplicates from a deeply nested list [/Body/Details/Item/Ref[@Type='Note']/Identifier]:

      <xsl:template name="DeDupe">
      <xsl:param name="list" />
      <xsl:param name="sep" select="', '" />

      <xsl:for-each select="$list">
          <xsl:variable name="curr" select="string(.)" />
          <xsl:variable name="i" select="position()" />
      
          <xsl:choose>
              <xsl:when test="count($list\[$i > position() and string(.) = $curr\]) > 0" />
              <xsl:otherwise>
                  <xsl:if test="position() != 1"><xsl:copy-of select="$sep" /></xsl:if>
                  <xsl:value-of select="$curr" />
              </xsl:otherwise>
          </xsl:choose>
      </xsl:for-each>
      

      </xsl:template>

      ...

      <xsl:call-template name="DeDupe">
      <xsl:with-param name="list" select="XPath expression" />
      </xsl:call-template>

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      C 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        I think what you're after is the xsl:param, combined with an xsl:call-tempalte or xsl:apply-templates call. For example, I use the following template to remove duplicates from a deeply nested list [/Body/Details/Item/Ref[@Type='Note']/Identifier]:

        <xsl:template name="DeDupe">
        <xsl:param name="list" />
        <xsl:param name="sep" select="', '" />

        <xsl:for-each select="$list">
            <xsl:variable name="curr" select="string(.)" />
            <xsl:variable name="i" select="position()" />
        
            <xsl:choose>
                <xsl:when test="count($list\[$i > position() and string(.) = $curr\]) > 0" />
                <xsl:otherwise>
                    <xsl:if test="position() != 1"><xsl:copy-of select="$sep" /></xsl:if>
                    <xsl:value-of select="$curr" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
        

        </xsl:template>

        ...

        <xsl:call-template name="DeDupe">
        <xsl:with-param name="list" select="XPath expression" />
        </xsl:call-template>

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Sort of - but I hoped to be able to call the stylesheet and pass in the variable, not run another transform to get it. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

        Richard DeemingR 1 Reply Last reply
        0
        • C Christian Graus

          Sort of - but I hoped to be able to call the stylesheet and pass in the variable, not run another transform to get it. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          So you're looking for something like:

          <xsl:template name="ListItems">
          <xsl:param name="list" />
          <xsl:param name="name" />

          <xsl:for-each select="$list\[contains(@name, $name)\]">
              **<-- Do something here -->**
          </xsl:for-each>
          

          </xsl:template>
          ...
          <xsl:call-template name="ListItems">
          <xsl:with-param name="list" select="XPath expression" />
          <xsl:with-param name="name" select="'M:XMLObject:functionname'" />
          </xsl:call-template>

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • C Christian Graus

            Does anyone know how to call a stylesheet and pass in a variable value ? I'm doing some docs using the XML generated by .NET and I want to pass in the node to look up for each page that documents one function, so I can pull out the parameters, etc. I hope to do this with one XSL, but at the moment it's something like <xsl;for-each select="[contains[@name, "M:XMLObject:functionname"]/> This works, but I'm not sure how to change 'functionname' dynamically, except by passing the xsl through another xsl sheet, and I don't want to do that, I want to set the value with a variable, and set the variable as I call the sheet. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            Christian - use xsl:param as a direct child of the xsl:stylesheet root element. You can then access the parameter in any XPath expression as $param-name. The parameters can be added using the addParameter of IXSLProcessor if you're accessing MSXML programmatically. If you're using a command-line tool, obviously, it depends, but MSXSL (Microsofts c-line XSL tool) has a "param=value" syntax. HTH Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

            C 1 Reply Last reply
            0
            • S Stuart Dootson

              Christian - use xsl:param as a direct child of the xsl:stylesheet root element. You can then access the parameter in any XPath expression as $param-name. The parameters can be added using the addParameter of IXSLProcessor if you're accessing MSXML programmatically. If you're using a command-line tool, obviously, it depends, but MSXSL (Microsofts c-line XSL tool) has a "param=value" syntax. HTH Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Wow - that is EXACTLY what I was looking for, thanks. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups