0
votes

I load follow XML in a XSL Variable

<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>

Now I like to filter the documents with the attribute lang="de" for and all invoice elements.

<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>

of course is not working is should be like this

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

but this give me an syntax error.

So may someone can help me with an idea.

EDIT Before 'Invoice' was hard coded in the filter.

I have add that

Thanks in advance.

T.S

2
"Invoice" s/b 'Invoice'Joel M. Lamsen
Thanks, i have edit this but still have the problem.Thaispookie

2 Answers

1
votes

using an xml input:

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

together with your lookup XML, and with this stylesheet:

<?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>

I have this output

<Invoice>92345</Invoice><Invoice>92346</Invoice>
0
votes

You XML isn't valid.. I can't see proper closing tags for Invoice and Offer.