为xml创建xls
我很难为以下xml创建xls转换文件:为xml创建xls,xml,xslt,Xml,Xslt,我很难为以下xml创建xls转换文件: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <ExportedData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Header> <
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<ExportedData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<StartDate>2015-02-02T00:00:00</StartDate>
<EndDate>2015-03-04T23:59:00</EndDate>
<RecordCount>4</RecordCount>
<Client />
<DocumentCount>0</DocumentCount>
</Header>
<Applicants>
<Applicant>
<ApplicantId>2176</ApplicantId>
<ModuleTypeId>1</ModuleTypeId>
<ApplicantInfo>
<Applications>
<Application>
<ApplicationId>6177</ApplicationId>
<Fields>
<Field>
<FieldName>Action Status</FieldName>
<FieldText>Submitted</FieldText>
</Field>
<Field>
<FieldName>BGCheck Result</FieldName>
<FieldText />
</Field>
<Field>
<FieldName>Date Hired</FieldName>
<FieldText />
</Field>
<Field>
<FieldName>Location Code</FieldName>
<FieldText>ManNY</FieldText>
</Field>
</Fields>
</Application>
</Applications>
</ApplicantInfo>
<ApplicantActionDocsInfo />
<ApplicantFormsInfo />
<ApplicantActionsInfo />
</Applicant>
2015-02-02T00:00:00
2015-03-04T23:59:00
4.
0
我理解这一点,但当尝试将其应用于我的xml时,它并没有完全起作用。我试着从一些非常简单的东西开始,但是我没有得到正确的输出
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Applicants Info</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>ApplicantId</th>
</tr>
<xsl:for-each select="ExportedData/Applicants/Applicant">
<tr>
<td><xsl:value-of select="ApplicantId"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
申请人信息
应用程序
同样,这只是我尝试过的一个简单测试用例(它只显示申请人Id)。我的最终目标是基本上显示xml中显示的所有信息。我做错了什么?当您更改此项时,您将获得applicationId
的值
<xsl:for-each select="Applicants/Applicant">
到
或
或模板的匹配模式:
<xsl:template match="/">
到
当前,您的模板与输入XML的根级别匹配,并且申请者
不是输入的第一个元素。更改此项时,您将获得applicationId
的值
<xsl:for-each select="Applicants/Applicant">
<xsl:template match="/">
到
或
或模板的匹配模式:
<xsl:template match="/">
到
当前,您的模板与输入XML的根级别匹配,申请人
不是输入的第一个元素。尝试编写模板,而不是为每个选择器编写模板。见下面的评论
<xsl:template match="/">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- match root - build html elements -->
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="ExportedData">
<xsl:apply-templates/>
</xsl:template>
<!-- Do nothing for the header -->
<xsl:template match="Header"/>
<!-- Build table for applicants -->
<xsl:template match="Applicants">
<h2>Applicants Info</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>ApplicantId</th>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<!-- for each applicant create a table row -->
<xsl:template match="Applicant">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<!-- for each Applicant/ApplicantId generate table cell -->
<xsl:template match="ApplicantId">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
<!-- you probably will want to add more stuff to the table, use templates to do so.-->
<xsl:template match="ModuleTypeId | ApplicantInfo | ApplicantActionDocsInfo | ApplicantFormsInfo | ApplicantActionsInfo"/>
</xsl:stylesheet>
申请人信息
应用程序
尝试编写模板,而不是为每个选择器编写模板。见下面的评论
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- match root - build html elements -->
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="ExportedData">
<xsl:apply-templates/>
</xsl:template>
<!-- Do nothing for the header -->
<xsl:template match="Header"/>
<!-- Build table for applicants -->
<xsl:template match="Applicants">
<h2>Applicants Info</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>ApplicantId</th>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<!-- for each applicant create a table row -->
<xsl:template match="Applicant">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<!-- for each Applicant/ApplicantId generate table cell -->
<xsl:template match="ApplicantId">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
<!-- you probably will want to add more stuff to the table, use templates to do so.-->
<xsl:template match="ModuleTypeId | ApplicantInfo | ApplicantActionDocsInfo | ApplicantFormsInfo | ApplicantActionsInfo"/>
</xsl:stylesheet>
申请人信息
应用程序
@John我刚刚用您的输入XML测试了调整后的XSL(添加了缺少的结束标记,因此我只有一个申请者
),并在加载XML时在Firefox中显示结果。如何编译XML?@John我刚刚用输入的XML测试了调整后的XSL(添加了缺少的结束标记,因此我只有一个申请者
),并在加载XML时在Firefox中显示结果。如何编译XML?由于每个applicationId都有多个元素,我很难正确使用applicationInfo元素。如何创建其他行?请更新您的问题,并向我展示您是如何尝试这样做的。由于每个applicationId都有多个元素,因此我很难正确获取applicationInfo元素。我将如何创建其他行?请更新您的问题,并向我展示您是如何尝试这样做的。在我看来,您似乎正在通过查看一些示例并从中推断来学习XSLT语言。这不是一个好的学习策略。通过这种方法,您永远不会学习语言的重要概念(例如,上下文如何工作)。给自己买本书,完成介绍性章节;你最终会为自己节省很多时间。而且,改变你的问题来回答一个答案是非常令人困惑的,因为现有的答案不再有任何意义。在适当的情况下,向问题中添加信息是有意义的,但是您永远不应该对答案中的某人建议的代码进行更正,否则线程将变得完全不可理解。在我看来,您似乎正在通过查看一些示例并从中推断来学习XSLT语言。这不是一个好的学习策略。通过这种方法,您永远不会学习语言的重要概念(例如,上下文如何工作)。给自己买本书,完成介绍性章节;你最终会为自己节省很多时间。而且,改变你的问题来回答一个答案是非常令人困惑的,因为现有的答案不再有任何意义。在适当的情况下,在问题中添加信息是有意义的,但决不能对答案中某人建议的代码进行更正,否则该线索将变得完全无法理解。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- match root - build html elements -->
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="ExportedData">
<xsl:apply-templates/>
</xsl:template>
<!-- Do nothing for the header -->
<xsl:template match="Header"/>
<!-- Build table for applicants -->
<xsl:template match="Applicants">
<h2>Applicants Info</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>ApplicantId</th>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<!-- for each applicant create a table row -->
<xsl:template match="Applicant">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<!-- for each Applicant/ApplicantId generate table cell -->
<xsl:template match="ApplicantId">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
<!-- you probably will want to add more stuff to the table, use templates to do so.-->
<xsl:template match="ModuleTypeId | ApplicantInfo | ApplicantActionDocsInfo | ApplicantFormsInfo | ApplicantActionsInfo"/>
</xsl:stylesheet>