2

I am using WSO2 BPS 3.2.0 and I want to assign namespace-uri of element to string. Problem is that I don't know element name at design time.

I have XML data

<message>
  <Header xmlns="http://schemas.org/Message"/>
  <Body xmlns="http://schemas.org/Message">
    <Container xmlns="http://schemas.org/Container/1.0">
      <Object>
        <document xmlns="http://schemas.org/doc/1.1">dfjgf...ash</document>
      </Object>
      <Object>
        <picture xmlns="http://schemas.org/pic/jpeg/2.0">we54uiytas...h</document >
      </Object>
    </Container>
  </Body>
</message>

I try to use XSLT transformation to get namespace

bpel:doXslTransform("getNamespace.xsl", $Var.message/tns1:Body/tns2:Container/tns2:Object[1])

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

   <xsl:template match="child::node[position()=1]">
     <xsl:value-of select="namespace-uri(.)"/>
   </xsl:template>

it returns nothing.
If I use output method text it returns all texts contained in xml data. Where I do mistake?

Eduard Nickel
  • 135
  • 1
  • 2
  • 13
  • Your question is not clear. Which element's namespace do you want to get and - since you won't know it's name - how will you identify it? – michael.hor257k Jan 18 '16 at 22:38
  • I want to get namespace of child element of Object. Maybe position is not required because there is not other child element in Object. – Eduard Nickel Jan 19 '16 at 08:05

1 Answers1

3

The following stylesheet:

XSLT 1.0

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

<xsl:template match="/">
     <xsl:value-of select="namespace-uri(*/*[1])"/>
</xsl:template>

</xsl:stylesheet>

will return the namespace of the first child of the root element.

In your example, the root element is message and its first child is Header - so the result here will be:

http://schemas.org/Message
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51