0
我試圖在我的XSL轉換過程中獲取iWantToGetThis.jpg
的值並將其放入<img>
。這是我的XML是如何結構:使用XSL獲取XML文檔中屬性的值
<article>
<info>
<mediaobject>
<imageobject>
<imagedata fileref='iWantToGetThis.jpg'>
下面是我想出了XSL:
<xsl:template name="user.header.content">
<xsl:stylesheet xmlns:d='http://docbook.org/ns/docbook'>
<img><xsl:attribute name="src">../icons/<xsl:value-of select='ancestor-or-self::d:article/info/mediaobject/imageobject/imagedata/@fileref' /></xsl:attribute></img>
</xsl:stylesheet>
</xsl:template>
圖像被添加到輸出,但src屬性設置爲「../icons/」,所以我假設它沒有在XML中找到fileref
屬性。這看起來對我完全有效,所以我不確定我錯過了什麼。
簡化代碼它只是在XPath表達式孩子缺少命名空間。 – Scribblemacher
當完整形式只包含一個''元素時,允許使用這種形式的樣式表。樣式表只包含該模板元素的內容。 [在這裏閱讀](http://www.w3.org/TR/xslt#result-element-stylesheet)。 –
Borodin
我正在使用的XSL更加充實。發佈後我意識到這不是一個很好的XSL示例...... – Scribblemacher