首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >对XML文件使用内联XSLT

对XML文件使用内联XSLT
EN

Stack Overflow用户
提问于 2011-08-20 21:40:41
回答 1查看 20K关注 0票数 18

我有一个XML文件和一个外部XSLT文件。

目前,在我的XML中,我使用href引用外部XSLT链接:

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
     <mytag>
         <t1> </t1>
         <t2> </t2>
         <t3> <t3>
     <mytag>

如何使用内联XSLT呢?这个是可能的吗?如果是,是如何实现的?

EN

回答 1

Stack Overflow用户

发布于 2013-03-20 09:18:02

对于跨客户端处理器的测试,请使用self-referencing stylesheet

代码语言:javascript
复制
<?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> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7132106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档