我是XSLT的新手,必须使用版本1.0和XPath 1.0,并感谢您的帮助。我尝试了不同的方法,虽然我已经接近解决方案,但我仍然缺少一些东西。我尝试过变量,但那些不能解决的问题因为你无法重复使用它们而我无法在XML / XPath中创建一个有意义的数组。我已尝试过循环,但我不希望每次都重复列标题...
关于输出/数据的格式: 它基本上是一个与一些人有关的清单(在这个例子中只有两个......可能是1个或更多)。
对于第一位客户 - 标题基本上是'申请人:'其次是第一栏中的申请人姓名和状态'在第二。在下一行是要检查第一列的项目和第二列中的状态。请注意,要检查的项目对于两个人都是相同的(在此示例中),但状态不同。
这种模式对于一些客户来说是重复的(这里有2个......但可以是任何数字)。下面我提供了我正在使用的适用XML和XSLT文件的一小部分。
这是我的XML:
<?xml version="1.0" encoding="UTF-8"?>
<LendingChecklistReport>
<LoanHdr>
...
</LoanHdr>
<ChecklistItems>
<Item>
<ChecklistType>SomeListType</ChecklistType>
<ChecklistSubTypeDesc>Alpha</ChecklistSubTypeDesc>
</Item>
<Item>
<ChecklistType>Applicant</ChecklistType>
<ChecklistSubTypeDesc>Cosmo Kramer</ChecklistSubTypeDesc>
<ItemDescription>Item to Check1</ItemDescription>
<Status>Pending</Status>
</Item>
<Item>
<ChecklistType>Applicant</ChecklistType>
<ChecklistSubTypeDesc>Adolph Credco</ChecklistSubTypeDesc>
<ItemDescription>Item to Check1</ItemDescription>
<Status>Waived</Status>
</Item>
<Item>
<ChecklistType>Applicant</ChecklistType>
<ChecklistSubTypeDesc>Cosmo Kramer</ChecklistSubTypeDesc>
<ItemDescription>Item to Check2</ItemDescription>
<Status>In Progress</Status>
</Item>
<Item>
<ChecklistType>Applicant</ChecklistType>
<ChecklistSubTypeDesc>Adolph Credco</ChecklistSubTypeDesc>
<ItemDescription>Item to Check2</ItemDescription>
<Status>Holding</Status>
</Item>
....
</ChecklistItems>
这是我的XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:decimal-format name="us" decimal-separator='.' grouping-separator=',' />
<xsl:param name="CurrentDate"/>
<!--<xsl:variable name="myVArray">
A
B
C
</xsl:variable>
<xsl:variable name="ApplicantNames" select="/*/Applicant" />-->
<xsl:template match="/LendingChecklistReport">
<!--myVArray:
<xsl:value-of select="$myVArray[1]"/>
ApplicantNames:
<xsl:value-of select="$ApplicantNames[1]"/>-->
<table style="width: 800px; padding: 0px; border: solid 0px blue;" cellspacing="0" border="0">
<tr>
<td class="Logo">logo</td>
</tr>
<tr>
<td colspan="2" class="Title">
Document Checklist
</td>
</tr>
<tr>
<td>
<!-- Header table -->
<xsl:apply-templates select="LoanHdr" />
</td>
</tr>
<tr>
<td class="Separator"></td>
</tr>
<tr>
<td>
<!-- Applicants table -->
<span class="Label">Applicants</span>
<xsl:apply-templates select="Applicants" />
</td>
</tr>
<tr>
<td class="Separator"></td>
</tr>
<tr>
<td>
<!-- Checklist table -->
<span class="Label">Checklist Items</span>
<table class="Table">
<!--<xsl:for-each select="Applicants/Applicant">
<xsl:sort select="ChecklistSubTypeDesc"/>
<tr>
<td class="ChecklistType, ColumnHeader" style="width: 50%">
Applicant: <xsl:value-of select="ApplicantName" />
</td>
<td class="ColumnHeader" style="text-align: center; width: 10%">Status</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Assigned To</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Due</td>
</tr>
<xsl:for-each select="/LendingChecklistReport/ChecklistItems/Item[ChecklistType = 'B']">
<xsl:sort select="ChecklistSubTypeDesc"/>
<tr>
<td style="color: red">
<xsl:value-of select="ItemDescription" />
<xsl:for-each select="Response">
<br />
<span class="Hint" style="margin-left: 10px">
Response: <xsl:value-of select="." />
</span>
</xsl:for-each>
</td>
<td style="text-align: center">
<xsl:value-of select="Status" />
</td>
<td style="text-align: center">
<xsl:value-of select="AssignedTo" />
</td>
<td style="text-align: center">
<xsl:value-of select="DueBy" />
</td>
</tr>
</xsl:for-each>
<tr>
<td class="Separator"></td>
</tr>
</xsl:for-each>-->
<tr>
<td class="ChecklistType, ColumnHeader" style="width: 50%">
Applicant:
</td>
<td class="ColumnHeader" style="text-align: center; width: 10%">Status</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Assigned To</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Due</td>
</tr>
<xsl:for-each select="ChecklistItems/Item[ChecklistType = 'B']">
<xsl:sort select="ChecklistSubTypeDesc"/>
<tr>
<td style="color: red">
<xsl:value-of select="ChecklistSubTypeDesc" />: <xsl:value-of select="ItemDescription" />
<xsl:for-each select="Response">
<br />
<span class="Hint" style="margin-left: 10px">
Response: <xsl:value-of select="." />
</span>
</xsl:for-each>
</td>
<td style="text-align: center">
<xsl:value-of select="Status" />
</td>
<td style="text-align: center">
<xsl:value-of select="AssignedTo" />
</td>
<td style="text-align: center">
<xsl:value-of select="DueBy" />
</td>
</tr>
</xsl:for-each>
<tr>
<td class="ChecklistType, ColumnHeader" style="width: 50%">Collateral</td>
<td class="ColumnHeader" style="text-align: center; width: 10%">Status</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Assigned To</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Due</td>
</tr>
<xsl:apply-templates select="ChecklistItems/Item[ChecklistType = 'C']" />
<tr>
<td class="Separator"></td>
</tr>
<tr>
<td class="ChecklistType, ColumnHeader" style="width: 50%">Loan</td>
<td class="ColumnHeader" style="text-align: center; width: 10%">Status</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Assigned To</td>
<td class="ColumnHeader" style="text-align: center; width: 20%">Due</td>
</tr>
<xsl:apply-templates select="ChecklistItems/Item[ChecklistType = 'L']" />
</table>
</td>
</tr>
<tr>
<td class="Separator"></td>
</tr>
</table>
</xsl:template>
<!-- Header table -->
<xsl:template match="LoanHdr">
...
</xsl:template>
<!-- Applicants table -->
<xsl:template match="Applicants">
<table class="Table">
<tr>
<td class="ColumnHeader">Name</td>
<td class="ColumnHeader">Type</td>
</tr>
<xsl:for-each select="Applicant">
<xsl:sort select="ApplicantName"/>
<tr>
<td>
<xsl:value-of select="ApplicantName" />
</td>
<td>
<xsl:value-of select="Relationship" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<!-- Applicants detail -->
<xsl:template match="/LendingChecklistReport/ChecklistItems/Item[ChecklistType = 'B']">
<!--<xsl:sort select="ChecklistType"/>-->
<tr>
<td style="color: red">
<xsl:value-of select="ItemDescription" />
<xsl:for-each select="Response">
<br />
<span class="Hint" style="margin-left: 10px">
Response: <xsl:value-of select="." />
</span>
</xsl:for-each>
</td>
<td style="text-align: center">
<xsl:value-of select="Status" />
</td>
<td style="text-align: center">
<xsl:value-of select="AssignedTo" />
</td>
<td style="text-align: center">
<xsl:value-of select="DueBy" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
这就是我想要完成的事情:
Applicant: Cosmo Kramer Status
Item to Check1 Pending
Item to Check2 In Progress
Applicant: Adolph Credco Status
Item to Check1 Waived
Item to Check2 Holding
答案 0 :(得分:0)
Thanx再次寻求帮助......在提供答案和链接之后,我能够想出一个解决方案。使用提供的相同XML,这是我使用的XSLT:
<xsl:key name="ApplicantNameCollection" match="/LendingChecklistReport/ChecklistItems/Item" use="ChecklistSubTypeDesc" />
<xsl:template match="/LendingChecklistReport">
<xsl:for-each select="ChecklistItems">
<table>
<xsl:for-each select="ChecklistItems/Item[ChecklistType='Applicant'][count(. | key('ApplicantNameCollection', ChecklistSubTypeDesc)[1]) = 1]">
<tr>
<td>Applicant: <xsl:value-of select="ChecklistSubTypeDesc" /></td>
<td>Status</td>
</tr>
<xsl:for-each select="key('ApplicantNameCollection', ChecklistSubTypeDesc)">
<tr>
<td><xsl:value-of select="ItemDescription" /></td>
<td><xsl:value-of select="Status" /></td>
</tr>
</xsl:for-each>
<tr>
<td class="Separator"></td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:template>
答案 1 :(得分:-1)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="Applicants" use="ChecklistSubTypeDesc" match="Item"/>
<xsl:template match="ChecklistItems">
<xsl:apply-templates select="Item[ChecklistType='Applicant']"/>
</xsl:template>
<xsl:template match="Item">
<xsl:variable name="currentName" select="ChecklistSubTypeDesc"/>
<xsl:if test="not(following::Item/ChecklistSubTypeDesc[text() = $currentName])">
<xsl:value-of select="ChecklistType"/>: <xsl:value-of select="$currentName"/><xsl:text> </xsl:text><xsl:value-of select="Status/name()"/>
<xsl:for-each select="key('Applicants',$currentName)"><xsl:text>
</xsl:text><xsl:apply-templates select="ItemDescription"/><xsl:text> </xsl:text><xsl:apply-templates select="Status"/>
</xsl:for-each>
</xsl:if><xsl:text>
</xsl:text>
</xsl:template>