XSLT は初めてですが、最近、XML を処理するために独自の xslt を作成する必要がありました。向上。
XSLT がテンプレートなどを使用していることは知っていますが、私の XSLT では、テストで繰り返し可能なものが多すぎると思います。減らすことはできますか?
ここに私のXSLTがあります:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="Today" />
<xsl:param name="ViewType" />
<xsl:template match="/">
<table>
<tr>
<th>Priority</th>
<th>Title</th>
<th>Due date</th>
</tr>
<xsl:apply-templates select="All_Results/Result">
<xsl:sort select="duedate" />
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="Result">
<xsl:variable name="varOverdue" select="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(duedate))) < ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))" ddwrt:cf_explicit="1"/>
<xsl:variable name="varOverduePlus14" select="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(duedate))) < ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))+12096000000000" ddwrt:cf_explicit="1"/>
<xsl:variable name="varOverdueToday" select="ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(duedate))) = ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))" ddwrt:cf_explicit="1"/>
<xsl:choose>
<xsl:when test="$ViewType='active'">
<xsl:if test="($varOverdue=0) and (taskstatus ='In Progress')">
<tr>
<td><xsl:value-of select="priority"/></td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
</a>
</td>
<td>
<xsl:value-of select="duedate"/>
</td>
</tr>
</xsl:if>
</xsl:when>
<xsl:when test="$ViewType='overdue'">
<xsl:if test="($varOverdue=1) and (taskstatus !='Completed')">
<tr>
<td><xsl:value-of select="priority"/></td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
</a>
</td>
<td>
<xsl:attribute name="style">
color:red;
</xsl:attribute>
<xsl:value-of select="duedate"/>
</td>
</tr>
</xsl:if>
</xsl:when>
<xsl:when test="$ViewType='upcoming'">
<xsl:if test="(taskstatus !='Completed') and ($varOverduePlus14=1)">
<tr>
<td><xsl:value-of select="priority"/></td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
</a>
</td>
<td>
<xsl:if test="$varOverdue=1">
<xsl:attribute name="style">
color:red;
</xsl:attribute>
</xsl:if>
<xsl:value-of select="duedate"/>
</td>
</tr>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
XML は次のようになります。
<All_Results>
<Result>
<id>1</id>
<workid>2258</workid>
...
</Result>
<Result>
<id>2</id>
<workid>4537</workid>
....
</Result>
...
</All_Results>
現在の XML を解析するように XSLT を改善する方法はありますか?