加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用内联XSLT作为XML文件

发布时间:2020-12-16 07:55:41 所属栏目:百科 来源:网络整理
导读:我有一个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?这可能吗?如果
我有一个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?这可能吗?如果是,怎么样?

是的,可以将XSLT嵌入到XML中.

XSLT是一个XML文件,所以您只需要确保将其放在XML文件的文档元素中,以使XML文件格式正确.

其实it is described in the XSLT specification:

07001

Normally an XSLT stylesheet is a complete XML document with the
xsl:stylesheet element as the document element. However,an XSLT
stylesheet may also be embedded in another resource. Two forms of
embedding are possible:

  • the XSLT stylesheet may be textually embedded in a non-XML
    resource,or
  • the xsl:stylesheet element may occur in an XML document other than
    as the document element.

To facilitate the second form of embedding,the xsl:stylesheet element
is allowed to have an ID attribute that specifies a unique identifier.

NOTE: In order for such an attribute to be used with the XPath id
function,it must actually be declared in the DTD as being an ID.

The following example shows how the xml-stylesheet processing
instruction [XML Stylesheet] can be used to allow a document to
contain its own stylesheet. The URI reference uses a relative URI with
a fragment identifier to locate the xsl:stylesheet element:

<?xml-stylesheet type="text/xml" href="#style1"?>
<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>
<head>
<xsl:stylesheet id="style1"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href="doc.xsl"/>
<xsl:template match="id('foo')">
  <fo:block font-weight="bold"><xsl:apply-templates/></fo:block>
</xsl:template>
<xsl:template match="xsl:stylesheet">
  <!-- ignore -->
</xsl:template>
</xsl:stylesheet>
</head>
<body>
<para id="foo">
...
</para>
</body>
</doc>

NOTE: A stylesheet that is embedded in the document to which it is to
be applied or that may be included or imported into an stylesheet that
is so embedded typically needs to contain a template rule that
specifies that xsl:stylesheet elements are to be ignored.

根据您计划如何利用它,可能不支持嵌入式样式表.例如,在IE 6/7/8中. There are some workarounds.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读