开发者

XML Stylesheet works with "xsltproc" in bash, but not in browser

I am trying to define an XSLT stylesheet to visuzalize XML in browser. I have a following stylesheet:

<html xsl:version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <head />
    <body>
      <div>
      <xmp>
        <xsl:copy-of select="/" />
      </xmp>
      </div>
    </body>
</html>

Running the "xsltproc" in bash has expected results which can be easily shown in browser. However, when attaching the stylesheet as

 开发者_开发技巧<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>

Only the text values are shown and the tags get lost. Tried with FF, Chrome, Safari.


I don't think combining the not standardized xmp element with XSLT will give you what you want. You could however use a stylesheet that serializes nodes to text, like http://lenzconsulting.com/xml-to-string/xml-to-string.xsl from http://lenzconsulting.com/xml-to-string/. You would import and use that as follows:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:import href="xml-to-string.xsl"/>

  <xsl:template match="/">
    <html>
        <head />
        <body>
          <div>
          <pre>
            <xsl:call-template name="xml-to-string">
              <xsl:with-param name="node-set" select="node()"/>
            </xsl:call-template>
          </pre>
          </div>
        </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

That should do within browsers, as long as you ensure all stylesheet modules are on the same server as the XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜