XPath for nodes where a subnode has attribute AND contains text

stevenssnail

New Member
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:\[code\]<?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>\[/code\]So I'd like to be able to apply templates to documents like\[code\] <xsl:apply-templates select="//Document[/DocumentEdition/Fields/Field[contains(@Name,'B?rn-Fritid')]/Option/text()>'']"/>\[/code\]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 \[code\]@Name\[/code\] contains a specific text.In the xml, using the input values:1 : B?rn-Fritidsliv => Selects the first document2 : B?rn-Fritidsklub => Selects the second document3 : B?rn-Fritid => Selects BOTH documentPlease point me in the right direction.
 
Back
Top