Web Analytics Made Easy -
StatCounter Variable variables in XSLT? - CodingForum

Announcement

Collapse
No announcement yet.

Variable variables in XSLT?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variable variables in XSLT?

    I'm passing an XSLT stylesheet the name of an element I want it to retrieve, but I have a problem. Here's the code I'm using at the moment to retrieve that element:

    <xsl:value-of select="$toget" />

    Which obviously doesn't work: It just returns whatever I passed it!

    Is there anyway to do this short of <xsl:when><xsl:choose>?
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #2
    XSLT doesn't have variables, only constants.

    How are you passing the name of the element?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

    Comment


    • #3
      In a variable called 'toget':
      Code:
      <xsl:param name="toget" />
      The name of the element I need to retrieve is in there. For example, it could be 'title' and I would need everything between <title> and </title>.

      ps: constants are variables
      Last edited by me'; Mar 7, 2004, 03:42 PM.
      David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
      W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

      Comment


      • #4
        Which parser are you using? With MSXML you might be able to do it by combining unparsed-entity-uri() and node-set...
        Marcus Tucker / www / blog
        Web Analyst Programmer / Voted SPF "ASP Guru"

        Comment


        • #5
          Originally posted by me'
          ps: constants are variables
          Are they? I thought constants were immutable?
          "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

          Comment


          • #6
            Constant and variable sorta give it all away. Constant always has the same value and can never change, which means it's always constant and a variable has a variable value which can change.

            Comment


            • #7
              Well, here you have a difference in computer language terms and mathematical terms. In computer languages the word 'variable' really should be thought of as 'container'. For example, you may declare a variable a constant, which by mathematical terminology would mean it is not a variable. In mathematical terms the difference is the mutability though.


              The reason for this?
              Computer languages use variables as containers, to which you define access rights. They may be read only, constants (which is not exactly the same as read only, though the difference is hard to explain), write only or read-write, but you still speak of them as variables.
              Last edited by liorean; Mar 8, 2004, 07:34 AM.
              liorean <[[email protected]]>
              Articles: RegEx evolt wsabstract , Named Arguments
              Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
              Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

              Comment


              • #8
                *cough* back on topic here?
                Originally posted by [email protected]
                Which parser are you using? With MSXML you might be able to do it by combining unparsed-entity-uri() and node-set...
                My parsing method is fairly complicated. I'm using PHP, and when I want to weed out a value, I whip up a XSLT stylesheet and use the XSLT functions with a few parameters passed to get it.

                Example: I have a stylesheet to parse a file containing a months' blog posts and spit it out in nicely formatted fashion:
                Code:
                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                
                <xsl:template match="blog">
                	<xsl:for-each select="post[position() = 1]">
                		<h2><a href="{uri}"><xsl:value-of select="date" /> {[mdash]} <xsl:value-of select="title" /></a></h2>
                		<xsl:for-each select="postbody/paragraph">
                			<p><xsl:value-of select="." /></p>
                		</xsl:for-each>
                	</xsl:for-each>
                	<xsl:for-each select="post[position()!=1]">
                		<h2><a href="{uri}"><xsl:value-of select="date" /> {[mdash]} <xsl:value-of select="title" /></a></h2>
                		<p><xsl:value-of select="description" /></p>
                	</xsl:for-each>  
                </xsl:template>
                
                </xsl:stylesheet>
                Last edited by me'; Mar 9, 2004, 03:20 PM.
                David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
                W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

                Comment

                Working...
                X