问题描述
是否有可能使用XSLT将XML转换为XML之外的其他东西?
例如。我想要最终的非xml 内容:
<内容>
< image url =file1.png>
< image url =file2.png>
...
< image url =filen.png>
< EndContent>
您注意到这个文档不是xml(甚至是html),但它确实有< elements>
。
是否可以使用XSLT生成非xml输出? b
$ b
非xml输出的另一个例子可能是:
< HTML>
< BODY>
< IMG src =file1.png>< BR>
< IMG src =file2.png>< BR>
...
< IMG src =filen.png>< BR>
< / BODY>
< / HTML>
你会注意到这个文件是 HTML ,因为在HTML IMG
和 BR
标签被禁止有结束标签。这与 xhtml 相反,后者是使用xml重新构造HTML的,其中所有元素都必须具有结束标记(因为xml中的每个标记都必须关闭)。
非xml输出的另一个例子可能是:
INSERT INTO文档(文件名)VALUES('file1.png')
INSERT INTO文档(文件名)VALUES('file2.png')
...
INSERT INTO文档(文件名)VALUES ('file3.png')
我可以制作我喜欢任何源xml,但一个例子可能是:
源xml:
code>< DocumentStore>
< Document type =image> file1.png< / Document>
< Document type =image> file2.png< / Document>
< Document type =image> filen.png< / Document>
< / DocumentStore>
或者:
<档案>
< User avatar =file1.png/>
< User avatar =file2.png/>
< User avatar =filen.png/>
< / Profiles>
您可以使用< xsl:output>
来指定输出格式,它不一定是xml,请参阅。然而,如果你输出的是html,即使你把结束标签放在了,现代浏览器也不应该抱怨,所以使用上面的例子,我相信所有的浏览器都可以: - $ / $>
< HTML>
< BODY>
< IMG src =file1.png>< / IMG>< BR>< / BR>
< IMG src =file2.png>< / IMG>< BR>< / BR>
...
< IMG src =filen.png>< / IMG>< BR>< / BR>
< / BODY>
< / HTML>
所以不太确定为什么你不想放置结束标记,除非我失踪
更新:新增非xml输出示例
给定此样式表: -
<?xml version =1.0encoding =UTF -8\" >?;
< xsl:stylesheet version =1.0
xmlns:xsl =http://www.w3.org/1999/XSL/Transform>
< xsl:output method =text/>
< xsl:template match =/ filenames>
< xsl:for-each select =文件名>
INSERT INTO Documents(Filename)VALUES('< xsl:value-of select =。/>')
< / xsl:for-each>
< / xsl:template>
< / xsl:stylesheet>
和这个输入xml: -
<?xml version =1.0encoding =UTF-8?>
<文件名>
<文件名> file1.png< /文件名>
<文件名> file2.png< /文件名>
<文件名> file3.png< /文件名>
< /文件名>
你得到的输出是这样的: - $ /
<$ (文件名)VALUES('file1.png')
INSERT INTO文件(文件名)VALUES('file2.png')
INSERT INTO文件(文件名)VALUES('file3.png')
Is it possible to use XSLT to transform XML into something other than XML?
e.g. i want the final non-xml content:
<Content>
<image url="file1.png">
<image url="file2.png">
...
<image url="filen.png">
<EndContent>
You're notice this document is not xml (or even html), but it does have <elements>
.
Is it possible, using XSLT, to generate non-xml output?
Another example of non-xml output might be:
<HTML>
<BODY>
<IMG src="file1.png"><BR>
<IMG src="file2.png"><BR>
...
<IMG src="filen.png"><BR>
</BODY>
</HTML>
You'll notice this document is HTML, because in HTML IMG
and BR
tags are forbidden from having a closing tag. This constrasts with xhtml, the reformulation of HTML using xml, where all elements are required from having a closing tag (because in xml every tag must be closed).
Another example of non-xml output might be:
INSERT INTO Documents (Filename) VALUES ('file1.png')
INSERT INTO Documents (Filename) VALUES ('file2.png')
...
INSERT INTO Documents (Filename) VALUES ('file3.png')
i can make up any source xml i like, but one example might be:
Source xml:
<DocumentStore>
<Document type="image">file1.png</Document>
<Document type="image">file2.png</Document>
<Document type="image">filen.png</Document>
</DocumentStore>
Or perhaps:
<Profiles>
<User avatar="file1.png" />
<User avatar="file2.png" />
<User avatar="filen.png" />
</Profiles>
You can use <xsl:output>
to specify the output format, which doesn't have to be xml, see this reference page.
However, if you are outputting html, no modern browser should complain even if you do put the closing tags, so using your example above, i believe all browser should be ok with :-
<HTML>
<BODY>
<IMG src="file1.png"></IMG><BR></BR>
<IMG src="file2.png"></IMG><BR></BR>
...
<IMG src="filen.png"></IMG><BR></BR>
</BODY>
</HTML>
So not too sure why you don't want to put the closing tag, unless i'm missing something.
Update: Added example of non xml output
Given this stylesheet:-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/filenames">
<xsl:for-each select="filename">
INSERT INTO Documents (Filename) VALUES ('<xsl:value-of select="." />')
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
and this input xml:-
<?xml version="1.0" encoding="UTF-8"?>
<filenames>
<filename>file1.png</filename>
<filename>file2.png</filename>
<filename>file3.png</filename>
</filenames>
You get output like this:-
INSERT INTO Documents (Filename) VALUES ('file1.png')
INSERT INTO Documents (Filename) VALUES ('file2.png')
INSERT INTO Documents (Filename) VALUES ('file3.png')
这篇关于XSLT:转换为非xml内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!