以下是XML文件的摘录:
<?xml version="1.0" encoding="utf-8"?>
<AssignmentHistory Version="171804">
<W20170828>
<StudentItems>
<Item>
<Name Counsel="13" NextCounsel="0" Completed="1">Name 1</Name>
<Type>Bible Reading (Main)</Type>
<Description>Bible Reading</Description>
</Item>
<Item>
<Name Counsel="50" NextCounsel="0" Completed="1">Name 2</Name>
<Type>#1 Student (Main)</Type>
<Description>Initial Call</Description>
</Item>
<Item>
<Name>Name A</Name>
<Type>Assistant</Type>
<Description>Initial Call</Description>
</Item>
<Item>
<Name Counsel="50" NextCounsel="0" Completed="1">Name 3</Name>
<Type>#2 Student (Main)</Type>
<Description>Return Visit</Description>
</Item>
<Item>
<Name>Name B</Name>
<Type>Assistant</Type>
<Description>Return Visit</Description>
</Item>
<Item>
<Name Counsel="33" NextCounsel="0" Completed="1">Name 4</Name>
<Type>#3 Student (Main)</Type>
<Description>Bible Study</Description>
</Item>
<Item>
<Name>Name C</Name>
<Type>Assistant</Type>
<Description>Bible Study</Description>
</Item>
</StudentItems>
</W20170828>
</AssignmentHistory>
这是XSL脚本:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msa="http://www.publictalksoftware.co.uk/msa">
<xsl:output method="html" indent="yes" version="4.01"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="//W3C//DTD XHTML 1.0 Transitional//EN"/>
<xsl:variable name="PubDB" select="document('MSA_PublisherDatabase.XML')"/>
<xsl:variable name="History" select="document('AssignHistory.XML')"/>
<xsl:template match="/">
<html>
<head>
<title>Students - Full History Report</title>
<!--<link rel="stylesheet" type="text/css" href="Custom Publisher Report.css"/>-->
</head>
<body>
<table style="width: 100%; border: 1px solid #000000; border-collapse: collapse;">
<xsl:apply-templates select="$PubDB/msa:PublisherDatabase/msa:Publishers/msa:Publisher">
<xsl:sort select="msa:Name" data-type="text" order="ascending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="msa:Publisher">
<tr>
<td colspan="5" style="border: 1px solid #000000">
<xsl:value-of select="msa:Name"/>
</td>
</tr>
<xsl:apply-templates select="$History/AssignmentHistory/*/StudentItems/Item[Name=current()/msa:Name]"/>
<tr>
<td colspan="5" style="border-top-style: solid; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px;">
<xsl:text> </xsl:text>
</td>
</tr>
</xsl:template>
<xsl:template match="Item">
<xsl:if test="position()=1">
<tr>
<td style="border: 1px solid #000000">
<xsl:text>Date</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Item</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Study Point</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Next Study Point</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Completed</xsl:text>
</td>
</tr>
</xsl:if>
<tr>
<td style="border: 1px solid #000000">
<xsl:value-of select="name(../..)"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Type"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Name/@Counsel"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Name/@NextCounsel"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Name/@Completed"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
工作正常。但我想从apply-templates
调用中的结果中排除:
<xsl:apply-templates select="$History/AssignmentHistory/*/StudentItems/Item[Name=current()/msa:Name]"/>
... Item
元素的Assistant
值为Type
。
目前我已将其更改为使用xsl:if
子句,但apply-templates
调用在更可能的情况下直接省略这些元素会更优雅:
日期 项目 研究点 下一个研究点 已完成
<xsl:if test="Type != 'Assistant'">
<tr>
<td class="CellNormal CellBorder">
<xsl:value-of select="name(../..)"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Type"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Name/@Counsel"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Name/@NextCounsel"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Name/@Completed"/>
</td>
</tr>
</xsl:if>