0
我試圖分析出那有我有麻煩了幾個特定的模板匹配情況下的FlowDocument屬性的節點。XSLT匹配,其中一個孩子的孩子有一個值
所以,下面的XAML文檔(這是通過打開Word,創建文本,然後複製到一個WPF的RichTextBox和提取的FlowDocument XAML中創建)。
<FlowDocument PagePadding="5,0,5,0" AllowDrop="True" NumberSubstitution.CultureSource="User" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Span xml:lang="en-us">
<Span.TextDecorations>
<TextDecoration Location="Underline" />
</Span.TextDecorations>
List Item 2
</Span>
<Run>
<Run.TextDecorations>
<TextDecoration Location="Underline" />
</Run.TextDecorations>
List Item 3
</Run>
</FlowDocument>
使用下面的XSLT,我想匹配的有有一個屬性值「位置=下劃線」子節點「TextDecoration」的跨度和運行的標籤。
<?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"
xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="p:FlowDocument">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="p:Run/Run.TextDecorations/TextDecoration[@Location='Underline']">
<u>
<xsl:apply-templates />
</u>
</xsl:template>
</xsl:stylesheet>
我知道上面的語句將無法正常工作,如果它實際上沒有它可能會選擇子節點,而不是說我希望得到的父節點。
我試圖讓輸出如下:
<html xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<body>
<u>List Item 2</u>
<u>List Item 3</u>
</body>
</html>
我也有問題,只是匹配「號碼:運行/ Run.TextDecorations」元素。使用Visual Studio,並逐步執行,它永遠不會找到我試圖找到的節點。
任何提示的歡迎!謝謝!
AHAH!命名空間的東西更有意義。這絕對是我錯過的!謝謝! – Bryan 2012-02-03 18:20:39