我需要使用XSL从XML生成简单的纯文本输出.由于我没有在网上找到任何好的,简洁的例子,我决定在这里发布我的解决方案.任何指向更好的例子的链接当然会受到赞赏:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="script/command" xml:space="preserve">at -f <xsl:value-of select="username"/> <xsl:value-of select="startTime/@hours"/>:<xsl:value-of select="startTime/@minutes"/> <xsl:value-of select="startDate"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
一些帮助我的重要事情:
此xslt的结果和所需输出为:
at -f alluser 23:58 17.4.2010
at -f ggroup67 7:58 28.4.2010
at -f ggroup70 15:58 18.4.2010
at -f alluser 23:58 18.4.2010
at -f ggroup61 7:58 22.9.2010
at -f ggroup60 23:58
21.9.2010 at -f alluser 3:58 22.9.2010
正如我所说,任何有关如何更优雅地做到这一点的建议将不胜感激.
后续行动2011-05-08:
这是我正在处理的xml的类型:
<script xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="script.xsd">
<command>
<username>alluser</username> …Run Code Online (Sandbox Code Playgroud)