2012-07-02 50 views
1

我必须将xslt写入wordml(2007)文档。有像下面这样的超链接。获取超链接的网址

< w:p w:rsidR="00FD086A" w:rsidRDefault="00425A76" w:rsidP="00FD086A"> 
< w: hyperlink r:id="rId4" w:history="1"> 
< w:r w:rsidR="00FD086A" w:rsidRPr="00425A76"> 
< w:rPr> 
< w:rStyle w:val="Hyperlink"/> 
< /w:rPr> 
< w:t>google</w:t> 
< /w:r> 
< /w:hyperlink> 
< /w:p> 

我想获取链接名称的url。在这里,我想获得“谷歌”链接的网址。我知道它存在于关系中,但我无法通过xslt访问它。有人知道吗? (大概写一个模板?)请帮助我!

+0

没人帮忙吗? – Setinger

+0

您的XML与您的描述不符。 URL在哪里?关系在哪里? –

+0

url是在一个普通词2007文档的“关系”中。它就像这样。 Setinger

回答

2

假设以下命名空间前缀宣称:

xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" 
xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" 
xmlns:rel="http://schemas.openxmlformats.org/package/2006/relationships" 
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 

以下XPath可用于选择在此使用“rId5”的w:hyperlink/@r:id(硬编码的值的值的URL的值例如):

/pkg:package 
    /pkg:part 
    /pkg:xmlData 
     /rel:Relationships 
     /rel:Relationship[@Id='rId5']/@Target 

你可以使用它在w:hyperlink模板匹配的情况下,产生一个HTML锚元素,像这样:

<xsl:template match="w:hyperlink"> 
    <a href="{/pkg:package 
       /pkg:part 
        /pkg:xmlData 
        /rel:Relationships 
         /rel:Relationship[@Id=current()/@r:id]/@Target}"> 
     <xsl:apply-templates/> 
    </a> 
</xsl:template> 
+0

你是超棒的!这就像一个魅力!我希望我能投票答复这个答案。但我需要更多的声誉。这真的很棒!^_^ – Setinger

+0

我还有一个问题。你也可以看一下吗?^_^ – Setinger

+0

我投了你的答案。^_ ^ – Setinger