我有XML:
<Job_post>
<Job_Details>
<Job_id>C_001</Job_id>
<Job_status>Filled</Job_status>
<Job_Posting_Details>
<Posting_Site>External Careers </Posting_Site>
</Job_Posting_Details>
</Job_Details>
<Job_Details>
<Job_id>Java_002</Job_id>
<Job_status>Open</Job_status>
<Job_Posting_Details>
<Posting_Site>External Careers </Posting_Site>
</Job_Posting_Details>
<Job_Posting_Details>
<Posting_Site>Internal</Posting_Site>
</Job_Posting_Details>
</Job_Details>
</Job_post>
我需要转换txt文件中不同行的条目,如
Job_id~|~Job_status~|~Posting_Site~
C_001~|~Filled~|~External Careers~
Java_002~|~Open~|~External Careers~
Java_002~|~Open~|~Internal~
请帮助我使用xslt格式将上面的xml转换为文本文件。
答案 0 :(得分:1)
请尝试以下XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:strip-space elements="*" />
<xsl:template match="Job_post">
<xsl:text>Job_id~|~Job_status~|~Posting_Site~</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="Job_Details/Job_Posting_Details">
<xsl:value-of select="normalize-space(../Job_id)" />
<xsl:text>~|~</xsl:text>
<xsl:value-of select="normalize-space(../Job_status)" />
<xsl:text>~|~</xsl:text>
<xsl:value-of select="normalize-space(Posting_Site)" />
<xsl:text>~</xsl:text>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
输出
Job_id~|~Job_status~|~Posting_Site~
C_001~|~Filled~|~External Careers~
Java_002~|~Open~|~External Careers~
Java_002~|~Open~|~Internal~
答案 1 :(得分:0)
你可以尝试使用XML解析器来获取数据。有可用于读取XML数据的SAX和DOM解析器。