Reinherd
Reinherd

Reputation: 5504

XSLT not rendering

I'm doing this simple XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl ="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:template match="/">
    <h1>El meu primer document XSLT</h1>
    <xsl:for-each select="pisos/pis">
      <strong>id:</strong>
      <xsl:value-of select="id"/>
     </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

And this is my XML file:

<Stock_pisos>
 <pisos>
    <pis>
      <id>1</id>
    </pis>
  </pisos>
</Stock_pisos>

However, the document just renders the H1 title.

Any tip?

Upvotes: 0

Views: 86

Answers (1)

Jasper
Jasper

Reputation: 534

You should select the root element first:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl ="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:template match="/">
    <h1>El meu primer document XSLT</h1>
      <xsl:for-each select="Stock_pisos/pisos/pis">
      <strong>id:</strong>
      <xsl:value-of select="id"/>
     </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Upvotes: 2

Related Questions