我有一个XML文件和一个外部XSLT文件。
目前,在我的XML中,我使用href引用外部XSLT链接:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<mytag>
<t1> </t1>
<t2> </t2>
<t3> <t3>
<mytag>
如何使用内联XSLT呢?这个是可能的吗?如果是,是如何实现的?
发布于 2013-03-20 09:18:02
对于跨客户端处理器的测试,请使用self-referencing stylesheet
<?xml version="1.0" encoding="utf-8"?>
<!--Reference the file name as the href value-->
<?xml-stylesheet type="text/xsl" href="html5.xml"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
>
<!-- Output HTML doctype with text/html content-type and without XML declaration-->
<xsl:output method="xml" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="yes" doctype-system="about:legacy-compat" />
<!-- Read the children of the stylesheet itself -->
<xsl:template match="xsl:stylesheet">
<xsl:apply-templates/>
</xsl:template>
<!-- Output the HTML markup-->
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="foo.css"/>
</head>
<body>
<div class="foo">
<span class="bar">
<span class="baz">1</span>
</span>
<!--Added comment to fill empty node-->
<span class="placeholder"><xsl:comment/></span>
</div>
<!-- Read matching templates -->
<xsl:apply-templates />
<!--Add comment to fill empty script tag-->
<script src="foo.js" type="application/x-javascript"><xsl:comment/></script>
</body>
</html>
</xsl:template>
<!-- Don't reprint text nodes within the xsl:stylesheet node -->
<xsl:template match="text()"/>
<!-- Read non-namespaced nodes within the xsl:stylesheet node -->
<xsl:template match="//node()[local-name() = name()]">
<xsl:if test="local-name() = 'foo'">
<xsl:variable name="foo" select="."/>
<input type="text" id="{$foo}" value="{$foo}"></input>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<test>
<foo>A</foo>
<foo>B</foo>
<foo>C</foo>
</test>
</xsl:stylesheet>
https://stackoverflow.com/questions/7132106
复制相似问题