我有一个如下的xml:
<?xml version="1.0" encoding="utf-8"?>
<GetSavedReportResponse>
<ResponseType>Success</ResponseType>
<FileModifiedDateTime>2012-01-03T17:05:04</FileModifiedDateTime>
<FileSizeBytes>7816</FileSizeBytes>
<FileDataFormat>XML</FileDataFormat>
<FileData>
<Zthes>
<term>
<termId>49555</termId>
<termUpdate>add</termUpdate>
<termName>Active Personnel</termName>
<termVocabulary>People Status Global</termVocabulary>
<termVocabulary>Global People Status</termVocabulary>
<termCategory>PDA</termCategory>
<termCategory>PDI</termCategory>
<termCategory>GLB</termCategory>
<relation weight="100">
<termId>49556</termId>
<relationType>EQ</relationType>
<termName>term name</termName>
<termVocabulary>term vocabulary</termVocabulary>
</relation>
<relation weight="100">
<termId>49557</termId>
<relationType>BT</relationType>
<termName>General Active Personnel</termName>
<termVocabulary>People Status Global Updated</termVocabulary>
</relation>
</term>
<term>
<termId>49556</termId>
<termUpdate>add</termUpdate>
<termName>Leave of Absence Personnel</termName>
<termVocabulary>People Status Global</termVocabulary>
<termCategory>GLB</termCategory>
<termCategory>PDI</termCategory>
<relation weight="100">
<relationType>BT</relationType>
<termId>49554</termId>
<termName>General Non-Active Personnel</termName>
<termVocabulary>People Status Global</termVocabulary>
</relation>
</term>
</Zthes>
</FileData>
</GetSavedReportResponse>
我需要将其转换为平面文件。为此,我编写了以下 xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" />
<xsl:template match="Zthes">
<xsl:text> </xsl:text>
<xsl:for-each select="term">
<xsl:text>"</xsl:text>
<xsl:text>GL</xsl:text>
<xsl:text>"</xsl:text>
<xsl:text>;</xsl:text>
<xsl:text>"</xsl:text>
<xsl:for-each select="termCategory">
<xsl:value-of select="." />
</xsl:for-each>
<xsl:text>"</xsl:text>
<xsl:text>;</xsl:text>
<xsl:text>"</xsl:text>
<xsl:for-each select="termVocabulary">
<xsl:value-of select="." />
</xsl:for-each>
<xsl:text>"</xsl:text>
<xsl:text>;</xsl:text>
<xsl:text>"</xsl:text>
<xsl:for-each select="relation/termVocabulary">
<xsl:value-of select="." />
</xsl:for-each>
<xsl:text>"</xsl:text>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
所以,输出应该是
“HDR”;“文本”;“20120112045620”;“F”
“GL”;“PDA”;“全球人物状态”;“术语词汇表”
“GL”;“PDA”;“人物状态”全球”;“全球人员状况全球更新”
“GL”;“PDA”;“全球人员状况”;“术语词汇”
“GL”;“PDA”;“全球人员状况”;“全球人员状况全球更新”
“GL” ;"PDI";"全球人员状态";"术语词汇表"
"GL";"PDI";"全球人员状态";"全球人员状态更新"
"GL";"PDI";"全球人员状态";"术语词汇"
"GL";"PDI";"全球人员状态";"全球人员状态更新"
"GL";"GLB";"人员状态全球";"术语词汇表"
"GL";"GLB";"全局人员状态";"全局人员状态已更新"
“GL”;“GLB”;“全球人员状况”;“术语词汇”
“GL”;“GLB”;“全球人员状况”;“人员状况全球更新”
“FTR”;12
使用我的 xsl,我开始单行:
“GL”;“PDAPDIGLB”;“人物状态全球全球人物状态”;“术语词汇人物状态全球更新”
并且标题行:
“HDR”;“PIGLSSTD”;“20120112045620”;“F”:
应附加在开头,以及页脚行
“FTR”;
在底部。