所以我有一个由其DTD验证的XML文件,现在我必须使用XSLT进行转换,该XSLT应该将每个用户的所有页面输出到XHTML文件。有人告诉我,我应该使用'for-each'但是我怎么能这样做,以便为每个用户输出一个文件? (每个输出文件应该是一个XHTML文件,其中包含用户信息,每个用户一个文件)
XML(示例):
<store>
<users>
<user id="user1">
<name username="user1">User 1</name>
<email>user1@email.com</email>
<birth birth_date=""></birth>
<mob_number>123</mob_number>
<address>Street1</address>
<picture></picture>
<basket></basket>
</user>
<user id="user2">
<name username="user2">User 2</name>
<email>user2@email.com</email>
<birth birth_date=""></birth>
<mob_number>123</mob_number>
<address>Street1</address>
<picture></picture>
<basket></basket>
</user>
<user id="user3">
<name username="user3">User 3</name>
<email>user3@email.com</email>
<birth birth_date=""></birth>
<mob_number>123</mob_number>
<address>Street1</address>
<picture></picture>
<basket></basket>
</user>
<user id="user4">
<name username="user4">User 4</name>
<email>user4@email.com</email>
<birth birth_date=""></birth>
<mob_number>123</mob_number>
<address>Street1</address>
<picture></picture>
<basket></basket>
</user>
</users>
</store>
谢谢
答案 0 :(得分:0)
正如@MartinHonnen所指出的,xsl:result-document
是要走的路
此答案将每个user
输出为名为HTML_userX
的单独文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:strip-space elements="*" />
<xsl:template match="/store/users">
<xsl:for-each select="user">
<xsl:result-document href="{concat('HTML_',@id)}" method="xhtml">
<xsl:copy-of select="." />
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>