1

I saw that there is an option to ignore namespace

 xpathUtil.getObjectValue("//*[local-name() = 'object name']")

is it possible to add more objetcs names

for example

  <Schema xmlns:m...... Namespace="app"
   xmlns:d = ....
  <complexType Name = "Comp>
  <EntityType Name = "a">
  <EntityType Name = "b">
  </Schema>

 <Schema xmlns:m...... Namespace="app2"
   xmlns:d = ....
  <complexType Name = "Comp2>
  <EntityType Name = "a2">
  <EntityType Name = "b2">
  </Schema>

is it possible to get the data of the attribute EntityType only for Schema= app ? ( meaning to get the result of a and b and not a2 and b2 )

2
  • Looking at your example I'm not quite sure which exact context you would like to use the namespace in: is at a) just a attribute to the <Schema> tag? In this case you can you can simply filtering by this attribute, e.g. "//Schema[@Namespace="XXX"]/...". Or is it b) a true namespace declaration to your <Schema> tag, in which case the example would be missing the namespace prefixes. Commented Nov 4, 2013 at 23:19
  • I meant it is possible don't use the namespace prefixes and to use the local-name() but to get more attribute like xpathUtil.getObjectValue("//*[local-name() = 'Schema']/EntityType") and also I want to get value of EntityType only for Schema that the Namespace is app Commented Nov 5, 2013 at 6:33

1 Answer 1

2

Assuming that a complete version of your input file might look like this

<?xml version="1.0" encoding="ISO-8859-1"?>
<Schemas>
  <ns1:Schema xmlns:ns1="app1" >
    <ns1:complexType Name = "Comp1">
      <ns1:EntityType Name = "a1"/>
      <ns1:EntityType Name = "b1"/>
    </ns1:complexType>
  </ns1:Schema>

  <ns2:Schema xmlns:ns2="app2">
    <ns2:complexType Name = "Comp2">
      <ns2:EntityType Name = "a2"/>
      <ns2:EntityType Name = "b2"/>
    </ns2:complexType>
  </ns2:Schema>
</Schemas>

the following XSLT shows how to filter the tags by the URI of the namespaceand the name of the namespace.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:variable name="ns_uri1" select="'app1'"/>
  <xsl:variable name="ns_uri2" select="'app2'"/>
  <xsl:variable name="ns_name1" select="'ns1'"/>
  <xsl:variable name="ns_name2" select="'ns2'"/>

  <xsl:template match="/Schemas">

    <apps>
      <app1_selected_by_namespace_uri>
        <xsl:copy-of select="*[local-name(.) = 'Schema' and namespace-uri(.)=$ns_uri1]"/>
      </app1_selected_by_namespace_uri>

      <app2_selected_by_namespace_uri>
        <xsl:copy-of select="*[local-name(.) = 'Schema' and namespace-uri(.)=$ns_uri2]"/>
      </app2_selected_by_namespace_uri>

      <app1_selected_by_namespace_name>
        <xsl:copy-of select="*[name(.) = concat($ns_name1, ':Schema')]"/>
      </app1_selected_by_namespace_name>

      <app2_selected_by_namespace_name>
        <xsl:copy-of select="*[name(.) = concat($ns_name2, ':Schema')]"/>
      </app2_selected_by_namespace_name>
    </apps>
  </xsl:template>

</xsl:stylesheet>

yielding the following output document

<?xml version="1.0" encoding="UTF-8"?>
<apps>
  <app1_selected_by_namespace_uri>
    <ns1:Schema xmlns:ns1="app1">
    <ns1:complexType Name="Comp1">
      <ns1:EntityType Name="a1"/>
      <ns1:EntityType Name="b1"/>
    </ns1:complexType>
  </ns1:Schema>
  </app1_selected_by_namespace_uri>
  <app2_selected_by_namespace_uri>
    <ns2:Schema xmlns:ns2="app2">
    <ns2:complexType Name="Comp2">
      <ns2:EntityType Name="a2"/>
      <ns2:EntityType Name="b2"/>
    </ns2:complexType>
  </ns2:Schema>
  </app2_selected_by_namespace_uri>
  <app1_selected_by_namespace_name>
    <ns1:Schema xmlns:ns1="app1">
    <ns1:complexType Name="Comp1">
      <ns1:EntityType Name="a1"/>
      <ns1:EntityType Name="b1"/>
    </ns1:complexType>
  </ns1:Schema>
  </app1_selected_by_namespace_name>
  <app2_selected_by_namespace_name>
    <ns2:Schema xmlns:ns2="app2">
    <ns2:complexType Name="Comp2">
      <ns2:EntityType Name="a2"/>
      <ns2:EntityType Name="b2"/>
    </ns2:complexType>
  </ns2:Schema>
  </app2_selected_by_namespace_name>
</apps>

In both cases the names are not hardcoded but given by parameters. I guess that one of the versions will suit your needs. You will find the XPath expression in the select attributes of the copy-of tags.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.