Home > database >  XSL XPatch for-each filtering for an attribute that doesnt exist
XSL XPatch for-each filtering for an attribute that doesnt exist

Time:09-23

XML ex.

  <Placemark>
    <ExtendedData><SchemaData schemaUrl="#OGRGeoJSON">
        <SimpleData name="OBJECTID">33503</SimpleData>
        <SimpleData name="Objecttype">VELOSTATION</SimpleData>
        <SimpleData name="Type_velo">ENKELZIJDIG</SimpleData>
        <SimpleData name="Ligging">PLEIN</SimpleData>
        <SimpleData name="Straatnaam">Koningin Astridplein (2018)</SimpleData>
        <SimpleData name="District">ANTWERPEN</SimpleData>
        <SimpleData name="Postcode">2018</SimpleData>
        <SimpleData name="Objectcode">VE_0000171</SimpleData>
        <SimpleData name="Gebruik">IN_GEBRUIK</SimpleData>
        <SimpleData name="Aantal_plaatsen">12</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>4.420745567350077,51.217857547604396</coordinates></Point>
  </Placemark>
  <Placemark>
    <ExtendedData><SchemaData schemaUrl="#OGRGeoJSON">
        <SimpleData name="OBJECTID">33504</SimpleData>
        <SimpleData name="Objecttype">VELOSTATION</SimpleData>
        <SimpleData name="Type_velo">DUBBELZIJDIG</SimpleData>
        <SimpleData name="Ligging">VOETPAD</SimpleData>
        <SimpleData name="Straatnaam">Paardenmarkt (2000)</SimpleData>
        <SimpleData name="Huisnummer">43</SimpleData>
        <SimpleData name="District">ANTWERPEN</SimpleData>
        <SimpleData name="Postcode">2000</SimpleData>
        <SimpleData name="Objectcode">VE_0000165</SimpleData>
        <SimpleData name="Gebruik">GEPLAND</SimpleData>
        <SimpleData name="Aantal_plaatsen">36</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>4.409111155407346,51.22513798273102</coordinates></Point>
  </Placemark>
  <Placemark>
    <ExtendedData><SchemaData schemaUrl="#OGRGeoJSON">
        <SimpleData name="OBJECTID">33505</SimpleData>
        <SimpleData name="Objecttype">VELOSTATION</SimpleData>
        <SimpleData name="Type_velo">ENKELZIJDIG</SimpleData>
        <SimpleData name="Ligging">PLEIN</SimpleData>
        <SimpleData name="Straatnaam">Koningin Astridplein (2018)</SimpleData>
        <SimpleData name="District">ANTWERPEN</SimpleData>
        <SimpleData name="Postcode">2018</SimpleData>
        <SimpleData name="Objectcode">VE_0000172</SimpleData>
        <SimpleData name="Aantal_plaatsen">12</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>4.420622573479942,51.217862009361745</coordinates></Point>
  </Placemark>

XSL for-each ex.

<xsl:for-each select="/Placemark/ExtendedData/SchemaData[SimpleData[@name = 'Gebruik'] != 'GEPLAND']">
<xsl:variable name="count" select="position()"/>
            <xsl:value-of select="$count"/>

So I need to create a filtering statement that gets everything except where "gebruik" = GEPLAND, and where its not present. I need to filter them out to get a correct ID for the database since im making an insert statement from this data.

I've tried a bunch of things but can't seem to get this working.

CodePudding user response:

I would think the path /Placemark/ExtendedData/SchemaData[SimpleData[@name = 'Gebruik'] = 'IN_GEBRUIK' or not(SimpleData[@name = 'Gebruik'])] implements your verbal description "filtering statement that gets both records where name="Gebruik = IN_GEBRUIK, and where its not present".

CodePudding user response:

--- edited ---

This predicate:

[not(SimpleData[@name='Gebruik'] = 'GEPLAND')]

will exclude records where SimpleData[@name='Gebruik'] has the value of "GEPLAND".


This predicate:

[SimpleData[@name='Gebruik'] != 'GEPLAND']

will exclude records where SimpleData[@name='Gebruik'] has the value of "GEPLAND" or SimpleData[@name='Gebruik'] does not exist at all.

  • Related