使用内联XSLT作为XML文件
我有一个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:
<?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>
根据您计划如何利用它,可能不支持嵌入式样式表.例如,在IE 6/7/8中. There are some workarounds. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |