You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by NOEL ALEX MAKUMULI <al...@hotmail.com> on 2009/04/28 23:29:21 UTC

Transformation Problem

Hello
I am kind of new on working with XML and XSL transformation..
however i have worked with XSL transformation for a short time only..

i have a small problem which i am facing and i do not really understand what is causing although i think the problem has something to do with the namespace..

i try to transform a SOAP_Message XML file to a normal XML file and i can get the values below the Header..meaning inside the the body element...

my XSL transformation looks like below...
<xsl:template match="/">
<Root>
<xsl:value-of select="SOAP-ENV:Envelope/soapenv:Header/cmn:timeStamp"/>
<xsl:value-of select="SOAP-ENV:Envelope/soapenv:Header/ns:getReportResponse/response/companyResponse/responseHeader/cmn:languageCode" />
<xsl:value-of select="SOAP-ENV:Envelope/soapenv:Header/ns:getReportResponse/response/companyResponse/responseHeader/cmn:responseStatus" />
</Root>

the timeStamp can be retrieved easily but however the field responseStatus can not be retrieved..i get an empty element..

can someone please tell me what i am doing wrong??

i have tried to search for a nice reason and people have just hinted the namespace issue and i have not managed to clear reason like what is the cause exactly...

my sample XML message is below::
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<cmn:timeStamp xmlns:cmn="http://www.companyName.com/XMLSchema/compMain.xsd">123445+0001</cmn:timeStamp>
</soapenv:Header>
<SOAP-ENV:Body>
<ns:getReportResponse xmlns:ns="http://www.companyName.com/company/">
<response xmlns:fs="http://www.companyName.com/XMLSchema/Company_4.xsd" xmlns:cmn="http://www.companyName.com/XMLSchema/compMain.xsd" xmlns:pr="http://www.companyName.com/XMLSchema/details.xsd" xmlns="http://www.companyName.com/XMLSchema/compMain3.xsd" xsi:SchemaLocation="http://www.companyName.com/XMLSchema/compMain3.xsd">
<companyResponse>
<responseHeader>
<cmn:languageCode xmlns:cmn="http://www.companyName.com/XMLSchema/compMain.xsd">com</cmn:languageCode>
<cmn:state xmlns:cmn="http://www.companyName.com/XMLSchema/compMain.xsd">1</cmn:state>
</responseHeader>
</companyResponse>
</response>

thanks for help in advance
proby

_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/

Re: Transformation Problem

Posted by Michael Ludwig <mi...@gmx.de>.
NOEL ALEX MAKUMULI schrieb am 29.04.2009 um 01:45:03 (+0300):
> 
> hello Michael,
> thanks for the quick and nice suggestions..

Hi Noel,

you're welcome.

> well i have to say that the issue which you have pointed out is the
> nine namespaces which some have no use..i asked the same question..
> 
> the issue which i am trying to achieve is to get the individual string
> value like status and language code..
> 
> if i remember correctly when i was doing transformation from one XMlL
> format to another XML format....like shown below:
> <Root>
> <child>child</child>
> </Root>
> the XSL transformation is pretty easy: <xsl:value-of
> select="/Root/child"> and will get the output child---

<xsl:value-of> gets the string value; <xsl:copy-of> copies the node.

> the issue is that the SOAP which comes has a lot of information which
> i really do not need... and i would like to use XSL to filter this
> information and remain with the few data which i would use..

Start out with the so-called "identity transform":

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

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

As step 1, run the transform, and look at the result to see the effect.
Then add the following rules one by one and repeat step 1 each time
around.

Add parsing and serialization instructions to get clean input and
output:

  <xsl:strip-space elements="*"/><!-- for parsing -->
  <xsl:output indent="yes"/><!-- for serialization -->

Replace the document element:

  <xsl:template match="/*"><!-- document element -->
    <Root>
      <xsl:apply-templates select="*"/>
    </Root>
  </xsl:template>

Replace the cmn:state element, and here, you need to add the namespace
to the stylesheet, and if you don't want it in the output, then you
exclude it:

<xsl:stylesheet version="1.0"
  xmlns:cmn="http://www.companyName.com/XMLSchema/compMain.xsd"
  exclude-result-prefixes="cmn"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="cmn:state">
    <child><xsl:apply-templates/></child>
  </xsl:template>

Final touch, add a rule to filter out everything else:

  <xsl:template match="*" priority="-0.4">
    <xsl:apply-templates select="*"/>
  </xsl:template>

> :-) i am not an expert in XSL and XML ...
> when i said normal XML file i meant the one which has root doctype..
> 
> i have tried the <xsl:copy-of> and this is the sample result::
> <soap_message><cmn:responseStatus
> xmlns:fs="http://www.asiakastieto.fi/XMLSchema/FinancialStatementCompany_4.03.xsd"
> xmlns:pr="http://www.asiakastieto.fi/XMLSchema/PopulationInformation_4.00.xsd">
> 1</cmn:responseStatus></soap_message>
> 
> is there any possible way to remove the namesapces here and have
> something clean like::
> <Root>
> 
> <child>child</child>
> 
> </Root>

See above.

> i am certainly heading to Mulberrytech.com ..
> 
> could you please suggest some nice readings of XSL and XSL
> namespaces..because i would like to learn more about this now..

Namespaces are just a mapping from prefixes to URIs (well, strings).
Not much to say. For XSLT, there are good sites and books:

* http://www.jenitennison.com/
* http://www.dpawson.co.uk/xsl/
* books by Jeni Tennison, Michael Kay, Evan Lenz, others

I hope this helps :-)

Michael Ludwig

Re: Transformation Problem

Posted by Michael Ludwig <mi...@gmx.de>.
NOEL ALEX MAKUMULI schrieb am 29.04.2009 um 00:29:21 (+0300):

> i try to transform a SOAP_Message XML file to a normal XML file

What's a normal XML file? :-)

> my XSL transformation looks like below...
> <xsl:template match="/">
> <Root>
> <xsl:value-of select="SOAP-ENV:Envelope/soapenv:Header/cmn:timeStamp"/>
> <xsl:value-of select="SOAP-ENV:Envelope/soapenv:Header/ns:getReportResponse/response/companyResponse/responseHeader/cmn:languageCode" />
> <xsl:value-of select="SOAP-ENV:Envelope/soapenv:Header/ns:getReportResponse/response/companyResponse/responseHeader/cmn:responseStatus" />
> </Root>
> 
> the timeStamp can be retrieved easily but however the field
> responseStatus can not be retrieved..i get an empty element..

Maybe that's because there is no cmn:responseStatus in your input?
Maybe you wanted to <xsl:copy-of select="//cmn:state"/> ?

> i have tried to search for a nice reason and people have just hinted
> the namespace issue and i have not managed to clear reason like what
> is the cause exactly...

It's easy to lose reason amidst such a namespace horror show as the one
you posted. A horror soap opera, more properly. Really looks like a
parody of SOAP. I counted nine namespaces, two of which are unused.

You may also want to check if you really want <xsl:value-of>, which
extracts the string value, or <xsl:copy-of>, which copies the nodes.

You can get a better answer if you tell us (or maybe the XSL-List at
Mulberrytech.com) what your desired output looks like.

Michael Ludwig