Search

Hi, I'm somewhat new to XSLT but so far I'm really liking it and can see how powerful it can be.

One problem I haven't been to figure out yet is how to get this HTML:

<body id="foo">

Where foo is the section name. I see that $root-page is the variable I want to use but I can simply output the way I would in, say, PHP.

I can do this:

<xsl:element name="body">
    <xsl:attribute name="id">
        <xsl:value-of select="$root-page" />
    </xsl:attribute>
    Do other stuff here
</xsl:element>

but is there a better way?

you can reference variables or xpath expressions in any element properties by wrapping them in curly braces.

<body id="{$root-page}">

Or you can use something like:

<body>
  <xsl:attribute name="id">
    <xsl:value-of select="$root"/>
  </xsl:attribute>
</body>

wouldn't that set his id to something like http://www.example.com though?

wouldn't that set his id to something like http://www.example.com though?

Yes, yes it would. But it's really just indicative of how you can set attributes, rather than the parameter you choose to output.

Ah, thanks so much. Yes, using <body id="{$root-page}"> is what I wanted.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details