-1

Trying to select an element based on the value of one of it's childrens

Im trying to do the same but it doesnt work.

XML:

    <customize>
      <name>InstallationZeitfenster</name>
      <dataType rvcd="2">Alphanumerisch</dataType>
      <value>Nachmittag</value>
    </customize>
    <customize>
      <name>InstallationGeplant</name>
      <dataType rvcd="3">Datum</dataType>
      <value>06.11.2019</value>
    </customize>
  </customize>

I want the text of the "value" node, with the node name = "InstallationGeplant" in it. Thats what i tried to do.

<xsl:value-of select="/*[local-name()='deviceManagement']/*[local-name()='deviceLocation']/*[local-name()='deviceInstallation']/*[local-name()='deviceInfo']/*[local-name()='device']/*[local-name()='customize']/*[local-name()='customize']/*[local-name()='name']/text() = 'InstallationGeplant'/*[local-name()='value']"/>

Has anyone some idea what i should do?

I have to access like this in to the nodes because of the namespaces. Thanks for the help

Melder
  • 1
  • I saw, that on this one is something similar, but not exactly like i did it https://stackoverflow.com/questions/9683054/xpath-to-select-element-based-on-childs-child-value/59192767#59192767 – Melder Dec 05 '19 at 12:08

2 Answers2

0

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
    <xsl:value-of select="descendant::value[preceding-sibling::name[1]='InstallationGeplant']"/>
</xsl:template>

</xsl:stylesheet>
Rudramuni TP
  • 1,256
  • 2
  • 15
  • 24
0

You could do simply:

<xsl:value-of select="customize[name='InstallationGeplant']/value"/>

This is from the context of the parent customize; your attempt suggests that the structure is deeper than what you show.


have to access like this in to the nodes because of the namespaces

No, you do not have to and should not. See: XSLT Transform doesn't work until I remove root node

michael.hor257k
  • 96,733
  • 5
  • 30
  • 46