2014-02-27 162 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