2014-02-27 73 views
0

我加載符合XML在變XSL Filter屬性和名稱()

<files> 
    <documents lang="en"> 
     <Invoice>22345</Invoice> 
     <Invoice>22346</Invoice> 
     <Offer>22345</Offer> 
     <Offer>22346</Offer> 
    </documents> 
    <documents lang="de"> 
     <Invoice>92345</Invoice> 
     <Invoice>92346</Invoice> 
     <Offer>92345</Offer> 
     <Offer>92346</Offer> 
    </documents> 
</files> 

一個XSL現在我喜歡和屬性LANG =「de」表示,所有的發票內容過濾的文件。

<xsl:variable name="documents" select="document('documents.xml')/files/documents" /> 
<xsl:variable name="documentName" select="'Invoice'" /> 

<xsl:apply-templates 
    mode="filter" 
    select="$documents[@lang='de' and name() = $documentName]"/> 

<xsl:template mode="filter" match="entrys[@lang] | *"> 
    <xsl:value-of select="."/> 
</xsl:template> 
當然

不工作是應該是這樣的

<xsl:apply-templates 
    mode="filter" 
    select="$documents[@lang='de' and */name() = $documentName]"/> 

但是這給我一個語法錯誤。

所以,有人可以幫助我一個想法。

編輯 之前'發票'被硬編碼在過濾器中。

我補充說,

在此先感謝。

T.S

+0

' 「發票」 單曲/ b''Invoice'' –

+0

謝謝,我已經編輯了這個,但仍然有問題。 – Thaispookie

回答

1

使用XML輸入:

<?xml version="1.0" standalone="no"?> 
<root> 
    <a>XXX</a> 
</root> 
與您的查找XML

在一起,並用這個樣式表:

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

    <xsl:output omit-xml-declaration="yes"/> 

    <xsl:variable name="documents" select="document('documents.xml')/files/documents" /> 

    <xsl:template match="root/a"> 
     <xsl:for-each select="$documents[@lang='de']/Invoice"> 
      <xsl:copy-of select="."/> 
     </xsl:for-each> 
    </xsl:template> 

</xsl:stylesheet> 

我有這樣的輸出

<Invoice>92345</Invoice><Invoice>92346</Invoice> 
+0

你的答案可以幫助我解決我的問題。 select =「$ documents [@ lang ='de']/* [name()= $ documentName]」/>。謝謝。 – Thaispookie

+0

我編輯了我的答案,它複製了節點。 –

0

你XML是無效的。我看不出發票,並提供適當的結束標記。

+0

現在關閉;-)謝謝 – Thaispookie