1

Can't see to complete this, in theory relatively simple task:

Find nodes Document where Field has attribute Name that contains specific text AND where subnodes Option has a value.

XML:

<?xml version="1.0" encoding="utf-8"?>
<root>
...
    <Documents>
    <Document Id="35330">
        <Name>The Name 1</Name>
        <DocumentEdition>
            <Fields>            
                <Field Name="Børn-Andet Godt" FieldType="CheckBoxGroup">
                    <Option Name="Billedkunst"></Option>           
                </Field>
                <Field Name="Børn-Fritidsklub" FieldType="CheckBoxGroup">
                    <Option Name="Fritidshjem"></Option>
                    <Option Name="Fritidsklub"></Option>
                    <Option Name="Ungdomsklubber"></Option>
                </Field>
                <Field Name="Børn-Fritidsliv" FieldType="CheckBoxGroup">
                    <Option Name="Natur- og fritidsforeninger"></Option>
                    <Option Name="Rollespil"></Option>
                    <Option Name="Spejder">B-Spejder</Option>
                </Field>
            </Fields>
        </DocumentEdition>
    </Document>
        <Document Id="35332">
            <Name>The Name 2</Name>
            <DocumentEdition>
                <Fields>
                    <Field Name="Børn-Andet Godt" FieldType="CheckBoxGroup">
                        <Option Name="Billedkunst"></Option>
                    </Field>
                    <Field Name="Børn-Fritidsklub" FieldType="CheckBoxGroup">
                        <Option Name="Fritidshjem">Fritidshjem</Option>
                        <Option Name="Fritidsklub"></Option>
                        <Option Name="Ungdomsklubber"></Option>
                    </Field>
                    <Field Name="Børn-Fritidsliv" FieldType="CheckBoxGroup">
                        <Option Name="Natur- og fritidsforeninger"></Option>
                        <Option Name="Rollespil"></Option>
                        <Option Name="Spejder"></Option>
                    </Field>
                </Fields>
            </DocumentEdition>
        </Document>
    </Documents>
..
</root>

So I'd like to be able to apply templates to documents like

  <xsl:apply-templates select="//Document[/DocumentEdition/Fields/Field[contains(@Name,'Børn-Fritid')]/Option/text()&gt;'']"/>

But that dosen't work.

Just to specify: Document must have text in an Option that is a subnode to the Field on which the @Name contains a specific text.

In the xml, using the input values:

1 : Børn-Fritidsliv => Selects the first document

2 : Børn-Fritidsklub => Selects the second document

3 : Børn-Fritid => Selects BOTH document

Please point me in the right direction.

4

1 回答 1

4

Drop the leading slash in the predicate and check whether there is an Option with content i.e. change

<xsl:apply-templates 
 select="//Document[/DocumentEdition/Fields/Field[contains(@Name,'Børn-Fritid')]/Option/text()&gt;'']"/>

to

<xsl:apply-templates 
 select="//Document[DocumentEdition/Fields/Field[contains(@Name,'Børn-Fritid') and Option[normalize-space()]]]"/>
于 2013-01-22T10:13:00.360 回答