参考我之前的问题 当我在根元素上有名字空间时,如何获得previous-sibling值? 我也有一些要求。输出根据要求假设是这样的。我得到空白的活动名称。
// Description Level Activity Name Activity ID
// =========== ============ ============= ======================================
// Main Entry Start Main Entry {00000000-0000-0000-0000-000000000000}
// Hello World! Information Main Entry {00000000-0000-0000-0000-000000000000}
// Test5 Verbose {3b081a36-43d5-4ecc-b381-628c33316205}
// alpha Start alpha {aa5a5b9c-4b24-43af-9f49-32656385e17d}
// Test7 Error alpha {aa5a5b9c-4b24-43af-9f49-32656385e17d}
// Test1 Information {d30741c2-da73-434a-8f0d-101f7ceb2228}
// Test11 Transfer Main Entry {00000000-0000-0000-0000-000000000000}
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl" ?>
<root>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Start">0</SubType>
<Correlation ActivityID="00000000-0000-0000-0000-000000000000" />
</System>
<ApplicationData>Main Entry </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Information">0</SubType>
<Correlation ActivityID="00000000-0000-0000-0000-000000000000" />
</System>
<ApplicationData>Hello World!</ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Verbose">0</SubType>
<Correlation ActivityID="3b081a36-43d5-4ecc-b381-628c33316205" />
</System>
<ApplicationData>Test5</ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Start">0</SubType>
<Correlation ActivityID="aa5a5b9c-4b24-43af-9f49-32656385e17d" />
</System>
<ApplicationData>alpha </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Error">0</SubType>
<Correlation ActivityID="aa5a5b9c-4b24-43af-9f49-32656385e17d" />
</System>
<ApplicationData>Test7 </ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Information">0</SubType>
<Correlation ActivityID="d30741c2-da73-434a-8f0d-101f7ceb2228" />
</System>
<ApplicationData>Test1</ApplicationData>
</E2ETraceEvent>
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<SubType Name="Transfer">0</SubType>
<Correlation ActivityID="00000000-0000-0000-0000-000000000000" />
</System>
<ApplicationData>Test11</ApplicationData>
</E2ETraceEvent>
</root>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:te="http://schemas.microsoft.com/2004/06/E2ETraceEvent"
xmlns:s="http://schemas.microsoft.com/2004/06/windows/eventlog/system"
xmlns:sd="http://schemas.microsoft.com/2004/08/System.Diagnostics"
xmlns:tr="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
exclude-result-prefixes="te s sd tr">
<xsl:output method="html" indent="no"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<div>
<div>
<table>
<thead>
<tr>
<th>Description</th>
<th>Level</th>
<th>Activity Name</th>
<th>Activity ID</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="//te:E2ETraceEvent">
<xsl:variable name="level">
<xsl:value-of select=".//s:SubType/@Name"/>
</xsl:variable>
<xsl:variable name="description">
<xsl:value-of select=".//te:ApplicationData/text()"/>
</xsl:variable>
<tr>
<!-- APPLICATION DATA -->
<td>
<xsl:value-of select="$description"/>
</td>
<!-- LEVEL -->
<td>
<xsl:value-of select="$level"/>
</td>
<!-- ACTIVITY NAME -->
<td>
<xsl:value-of select="((. | preceding-sibling::E2ETraceEvent)[System/SubType/@Name='Start'])[last()]/ApplicationData"/>
</td>
<!-- ACTIVITY ID -->
<td>
<xsl:value-of select=".//s:Correlation/@ActivityID"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
在处理源XML中的元素时,这部分代码不使用所需的前缀 - 因此未选择任何内容:
<!-- ACTIVITY NAME -->
<td>
<xsl:value-of select="((. | preceding-sibling::E2ETraceEvent)[System/SubType/@Name='Start'])[last()]/ApplicationData"/>
</td>
它可能看起来更像是这样:
<!-- ACTIVITY NAME -->
<td>
<xsl:value-of select="((. | preceding-sibling::te:E2ETraceEvent)[s:System/s:SubType/@Name='Start'])[last()]/te:ApplicationData"/>
</td>
我说可能是,因为修复后收到的结果与您在帖子开头显示的结果不符。但这是一个在你之前的问题中已经(或应该已经)解决过的问题。