2014-02-27 2 views
0

나는 이제에 대한 속성 LANG = "드"모든 송장 요소와 문서를 필터링 할XSL 필터 속성과 이름()

<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에 나온 XML을로드합니다. 물론

<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

' "송장"'S : 당신 조회 XML과 함께

<?xml version="1.0" standalone="no"?> <root> <a>XXX</a> </root> 

을,이 스타일 시트와/b'Invoice'' –

+0

고마워, 편집했지만 문제가 여전히있다. – Thaispookie

답변

1
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

이제 닫으십시오 ;-) thanks – Thaispookie