基于XML文件数据的XSLT过滤
我有以下XSLT:基于XML文件数据的XSLT过滤,xml,xslt,Xml,Xslt,我有以下XSLT: <xsl:template match="Table"> <tr> <td> <font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap"> <xsl:value-of select="PRG_DESCRIPTION"
<xsl:template match="Table">
<tr>
<td>
<font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap">
<xsl:value-of select="PRG_DESCRIPTION"/>
</font>
</td>
<td>
<font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap">
<xsl:value-of select="DAYS_LEFT"/>
</font>
</td>
<td>  </td>
<xsl:if test="ACTIVE = 0">
<td style="top: 2px">
<form name="myform" onsubmit="popupform(this, 'join');" action="../LogOnSection/SetCourseStart.aspx" method="post">
<input type="hidden" name="CourseID">
<xsl:attribute name="value">
<xsl:value-of select="EEDO_COURSE_ID"/>
</xsl:attribute></input>
<input type="hidden" name="UserID"><xsl:attribute name="value">
<xsl:value-of select="CLI_RID"/>
</xsl:attribute></input>
<input type="hidden" name="EventCode"><xsl:attribute name="value">
<xsl:value-of select="EVE_EVENT_CODE"/>
</xsl:attribute></input>
<input type="hidden" name="DateCreated">
<xsl:attribute name="value">
<xsl:value-of select="DATE_CREATED"/>
</xsl:attribute>
</input>
<input name="Submit" type="submit" value="Go"/>
<br>
</br>
</form>
</td>
</xsl:if>
</tr>
</xsl:template>
这是如何从数据库“加载”的,GM.AlasData.ActiveOLCourses
是一个web服务函数,用于查询数据库中传递的参与者ID的活动课程
s = New StringReader(GM.AlasData.ActiveOLCourses(ParticipantID))
xtr = New XmlTextReader(s)
Dim XMLDoc = New XPathDocument(xtr)
Dim XSLTDoc = New XslCompiledTransform
XSLTDoc.Load(Server.MapPath("ListCourseFormat.xslt"))
'Transform XMLDoc and dump HTML results to stringwriter -> sw
XSLTDoc.Transform(XMLDoc, Nothing, sw)
顺便说一句,据我所知,它似乎在使用v1.0。您只想输出那些在第二个“program_codes”XML文档中没有提到
值的
元素
<!-- open extra XML document -->
<xsl:variable name="refDoc" value="document('path/to/program_codes.xml')" />
<!-- collect your IDs from that document -->
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />
<xsl:template match="/">
<table>
<!-- process only those nodes where the IDs don't match -->
<xsl:apply-templates select="//Table[not(EVE_EVENT_CODE = $refIDs)]" />
</table>
</xsl:template>
<xsl:template match="Table">
<tr>
<td style="font: 12pt Verdana; color: white; vertical-align: top; white-space: nowrap">
<xsl:value-of select="PRG_DESCRIPTION" />
</td>
<td style="font: 12pt Verdana; color: white; vertical-align: top; white-space: nowrap">
<xsl:value-of select="DAYS_LEFT" />
</td>
<td>  </td>
<xsl:if test="ACTIVE = 0">
<td style="top: 2px">
<form action="../LogOnSection/SetCourseStart.aspx" method="post" onsubmit="popupform(this, 'join');">
<input type="hidden" name="CourseID" value="{EEDO_COURSE_ID}" />
<input type="hidden" name="UserID" value="{CLI_RID}" />
<input type="hidden" name="EventCode" value="{EVE_EVENT_CODE}" />
<input type="hidden" name="DateCreated" value="{DATE_CREATED}" />
<input name="Submit" type="submit" value="Go" />
<br />
</form>
</td>
</xsl:if>
</tr>
</xsl:template>
提示:
- 使用属性值模板(上面的大括号)可以节省大量的键入工作
- 将所有内联样式放在一个单独的CSS文件中,并使用CSS类。请放下那些
标签,把它们从你的记忆中抹去 - 间隔柱也不再是最先进的。使用CSS获得您想要的边距,而不是使用
代码>
编辑OP的评论后,我建议使用以下修改后的解决方案:
<!-- open extra XML document -->
<xsl:variable name="refDoc" value="document('path/to/program_codes.xml')" />
<!-- collect your IDs from that document -->
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />
<xsl:template match="/">
<table>
<xsl:apply-templates select="//Table" />
</table>
</xsl:template>
<xsl:template match="Table">
<!-- effectively: if there's no refID which is contained in the current event code -->
<xsl:if test="count($refIDs[contains(current()/EVE_EVENT_CODE, .)]) = 0">
...
</xsl:if>
</xsl:template>
...
所以您有两个XML文件,对吗?主要输入是什么样子的,你认为哪些元素是“记录”显示的?您是否有各种表
元素,并且只想处理第二个元素中存在EVE\u EVENT\u code
的元素?您使用XSLT1还是XSLT2?我不知道使用的是什么版本。数据来自数据库,并转换为XML。否,我只想显示在EVE\u EVENT\u code
1中没有id
的代码。向我们展示原始XML数据。2.找出您使用的处理器:看起来不错,但EVE\U事件代码可能是这样的:20170204WBRME
或20170301OLCC
我需要它只匹配第一个处理器,因为RME
在代码中而CC
不在代码中。这就是为什么您应该包含XML,而不是模糊的英文描述您的XML。我应该怎么猜到这个?参见修改后的答案。它应该给你一个正确的想法。很抱歉,由于数据是从数据库生成的,所以我无法将数据保存到文件中。我该怎么办:
?见我更新的帖子。
<!-- open extra XML document -->
<xsl:variable name="refDoc" value="document('path/to/program_codes.xml')" />
<!-- collect your IDs from that document -->
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />
<xsl:template match="/">
<table>
<!-- process only those nodes where the IDs don't match -->
<xsl:apply-templates select="//Table[not(EVE_EVENT_CODE = $refIDs)]" />
</table>
</xsl:template>
<xsl:template match="Table">
<tr>
<td style="font: 12pt Verdana; color: white; vertical-align: top; white-space: nowrap">
<xsl:value-of select="PRG_DESCRIPTION" />
</td>
<td style="font: 12pt Verdana; color: white; vertical-align: top; white-space: nowrap">
<xsl:value-of select="DAYS_LEFT" />
</td>
<td>  </td>
<xsl:if test="ACTIVE = 0">
<td style="top: 2px">
<form action="../LogOnSection/SetCourseStart.aspx" method="post" onsubmit="popupform(this, 'join');">
<input type="hidden" name="CourseID" value="{EEDO_COURSE_ID}" />
<input type="hidden" name="UserID" value="{CLI_RID}" />
<input type="hidden" name="EventCode" value="{EVE_EVENT_CODE}" />
<input type="hidden" name="DateCreated" value="{DATE_CREATED}" />
<input name="Submit" type="submit" value="Go" />
<br />
</form>
</td>
</xsl:if>
</tr>
</xsl:template>
<!-- open extra XML document -->
<xsl:variable name="refDoc" value="document('path/to/program_codes.xml')" />
<!-- collect your IDs from that document -->
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />
<xsl:template match="/">
<table>
<xsl:apply-templates select="//Table" />
</table>
</xsl:template>
<xsl:template match="Table">
<!-- effectively: if there's no refID which is contained in the current event code -->
<xsl:if test="count($refIDs[contains(current()/EVE_EVENT_CODE, .)]) = 0">
...
</xsl:if>
</xsl:template>