Converting to xsl showing style sheet string

I am trying to convert xml to html using an xsl transform file.

test.xml:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<website>
  <header/>
  <content>
    <b>First Line</b>
  </content>
</website>

      

test.xsl:

<xsl:output method="html" encoding="UTF-8" indent="yes"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="/website">
    <html>
        <head/>
        <body>
            <xsl:apply-templates select="header|content/*"/>
        </body>
  </html>
</xsl:template>

 <xsl:template match="header">
   <b>Header</b>
   <br/>
  </xsl:template>

</xsl:stylesheet>

      

The converted html file looks like this:

<?xml-stylesheet type="text/xsl" href="test.xsl" ><html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body><b>Header</b><br><b>First Line</b></body>
</html>

      

We can see that everything is being converted correctly, but in the output the style line is displayed at the top. How can I get rid of it? I did it using IE and then looked at the source. Then I tried using msxsl.exe to convert the file and got the same result.

If I remove the id conversion from the xsl file the problem goes away, but it doesn't convert the result correctly.

+3


source to share


1 answer


You can add an empty template to remove processing instructions such as <?xml-stylesheet ?>

:



....
....

<xsl:template match="header">
    <b>Header</b>
    <br/>
</xsl:template>

<xsl:template match="processing-instruction()"/>

      

+3


source







All Articles