0

Good morning!

I have this XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Relatorio.xsl"?>
<relatório id="LPROG" xmlns="http://www.dei.isep.ipp.pt/lprog"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.dei.isep.ipp.pt/lprog Relatorio.xsd">
    <páginaRosto>
        <tema>oRolhas</tema>

        <!--Bunch of other fields-->

    </páginaRosto>

    <!--Bunch of other fields-->

</relatório>

The XML is correctly formed and validated using the given XSD.

After applying this simple .xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
        <html>
            <head>
                <title/>
            </head>
            <body>
                <h1 align="center">Relatório Trabalho</h1>
                <xsl:apply-templates select="relatório/páginaRosto"/>
            </body>
        </html>
    </xsl:template>


    <xsl:template match="páginaRosto">
        <h1>Page</h1>
        <h2>Tema:
            <xsl:value-of select="tema"/>
        </h2>
    </xsl:template>



</xsl:stylesheet>

The output is:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body><h1 align="center">Relatório Trabalho</h1></body>
</html>

It is not "printing" the "páginaRosto" template, and I can't figure out why. Is there any problem with my XPath expressions or even with the XML file?

Thanks in advance

Diogo Santos
  • 780
  • 4
  • 17

2 Answers2

0

The xml defines a default namespace xmlns="http://www.dei.isep.ipp.pt/lprog"

To match elements in the default namespace the XPath expression must use the same namespace (but must define a non empty prefix):

<xsl:apply-templates 
    xmlns:p="http://www.dei.isep.ipp.pt/lprog"      
    select="p:relatório/p:páginaRosto"/>
wero
  • 32,544
  • 3
  • 59
  • 84
0

XML:

<relatório id="LPROG" xmlns:lp="http://www.dei.isep.ipp.pt/lprog" 
    ...
</relatório>

XSL:

<xsl:apply-templates xmlns:lp="http://www.dei.isep.ipp.pt/lprog" select="relatório/páginaRosto"/>

Result:

<html>
   <head>
      <title/>
   </head>
   <body>
      <h1 align="center">Relatório Trabalho</h1>
      <h1>Page</h1>
      <h2>Tema:
            oRolhas</h2>
   </body>
</html>
Bor Laze
  • 2,458
  • 12
  • 20