2013-02-14 68 views
0

我正在學習xml和XSLT。XSLT使用doc函數進行xml

,我想創建可以從family.xml文件

我有顯示所有名的XSLT文件...

文檔( 「family.xml」)// NAME

但是,我不太確定在XSLT文件上使用doc函數的語法。

有人能幫助我嗎?

感謝

+0

請問你的XSL樣子現在呢? – Vinit 2013-02-15 01:15:09

+0

您使用什麼來處理XSLT?您擁有的XPath可以作爲XQuery執行,並在不使用XSLT的情況下正確返回您想要的內容。 – 2013-02-15 01:33:01

回答

1

讓我們說你filename.xml中是這樣的:

<?xml version="1.0"?> 
<bookstore> 
    <book category="COOKING"> 
    <title lang="en">Everyday Italian</title> 
    <author>Giada De Laurentiis</author> 
    <year>2005</year> 
    <price>30.00</price> 
    </book> 
    <book category="CHILDREN"> 
    <title lang="en">Harry Potter</title> 
    <author>J K. Rowling</author> 
    <year>2005</year> 
    <price>29.99</price> 
    </book> 
    <book category="WEB"> 
    <title lang="en">Learning XML</title> 
    <author>Erik T. Ray</author> 
    <year>2003</year> 
    <price>39.95</price> 
    </book> 
</bookstore> 

要得到所有的標題:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> 

<!-- match root documents tag --> 
<xsl:template match="/"> 
<xsl:apply-templates select="document('filename.xml')/bookstore//title/node()" mode="document"/> 
</xsl:template> 


    <xsl:template match="/" mode="document"> 
    <xsl:copy-of select="."/> 
    </xsl:template> 

</xsl:stylesheet> 
+0

爲什麼在select中使用'xsl:copy-of'和'document()'路徑時爲什麼要使用'xsl:apply-templates'? – 2013-02-15 01:31:14

+0

@丹尼爾:只是一個首選項,因爲沒有提到的問題..你可以使用複製或價值或應用模板等這個 – Vinit 2013-02-15 01:38:13

+0

謝謝大聲笑它真的幫助我理解大聲笑 – 2013-02-15 02:07:10