Click to See Complete Forum and Search --> : xpath-cant get root element with attributes


Leon945
08-27-2010, 06:48 PM
Hello,
Im kind of new to xpath, so this might have a simple solution..
Im trying to transform an xml documento into another using xsl..

this is my original xml document:

<?xml version="1.0" encoding="UTF-8"?>
<systemResponse uid="a127366s62242081" xmlns="http://mpowerlabs.com/jetphire/external/1">
<responseCode>0</responseCode>
</systemResponse>


this is my XSL ..

<Message xsl:version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<ContentType></ContentType>
<ResourceName></ResourceName>
<Security></Security>
<Report>
<ValueList>
<Value>
<Attribute1><xsl:value-of select="/systemResponse/responseCode"/></Attribute1>
</Value>
</ValueList>
</Report>
</Message>


Im using an apache library to do the transformation..
The problem is, its not placing any value inside the attribute1 tag.

I noticed that if a i remove the attributes (uid,xmlns) from the systemResponse root tag, so that its like this

<?xml version="1.0" encoding="UTF-8"?>
<systemResponse>
<responseCode>0</responseCode>
</systemResponse>


it works.. it places the "0" inside the attribute1 tag..

whats going on here.. what can i do?

thanks in advance..

Charles
08-29-2010, 12:02 PM
That one attribute, xmlns, is a namespace designation. It means that you have no systemResponse element. It's really a http://mpowerlabs.com/jetphire/external/1:systemResponse element. Fortunately there is a shorthand.<Message xsl:version="1.0"
xmlns:mp="http://mpowerlabs.com/jetphire/external/1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<ContentType></ContentType>
<ResourceName></ResourceName>
<Security></Security>
<Report>
<ValueList>
<Value>
<Attribute1><xsl:value-of select="/mp:systemResponse/mp:responseCode"/></Attribute1>
</Value>
</ValueList>
</Report>
</Message>

Leon945
08-29-2010, 01:09 PM
oh man..
i knew it had to be somthing simple..
thanks very much..

i have another question.. i don't know if you can help me with it...
i see that my resulting xml, which is this:

<?xml version="1.0" encoding="UTF-8"?>
<Message xmlns:mp="http://mpowerlabs.com/jetphire/external/1">
<ContentType/>
<ResourceName/>
<Security/>
<Report>
<ValueList>
<Value>
<Attribute1>0</Attribute1>
</Value>
</ValueList>
</Report>
</Message>


has the xmlns attribute too...
is there a way to transform the xml, so that the resulting xml doesnt have that attribute?

Leon945
08-29-2010, 02:23 PM
nevermind.. i dont really need that..

thanks alot for your answer, really helped me alot

:D

thanks again