Mariano
Mariano

Reputation: 23

Get via XPATH to value of the tag

I have a doubt about XSLT. I'm trying get via XPATH to value of the tag but I don't know how can I do it.

I'm tryng acces with this XPTAH:

<xsl:copy-of select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role=&apos;C&apos; and ./@id=&apos;atom1&apos;]/*/Table1/Nombre">

but it's impossible.

I also tried with code:

<xsl:copy-of select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role=&apos;C&apos; and ./@id=&apos;atom1&apos;]/DescargarFicheroPendienteResponse/DescargarFicheroPendienteResult/Table1/Nombre">

I think th problem is the tag:

This is the example XML:

<Payload Role="C" id="atom1" statusNo="0" statusMsg="success" reference="atom2" payload="atom2" calltype="solicit response (call/reply)" adapter="WSAS">  
    <http.header>  
        <http.header.info id="X-AspNet-Version" value="2.0.50727"/>  
        <http.header.info id="Date" value="Wed, 24 Jul 2013 10:23:53 GMT"/>  
        <http.header.info id="Content-Length" value="494"/>  
        <http.header.info id="MicrosoftOfficeWebServer" value="5.0_Pub"/>  
        <http.header.info id="Content-Type" value="text/xml; charset=utf-8"/>  
        <http.header.info id="Server" value="Microsoft-IIS/6.0"/>  
        <http.header.info id="X-Powered-By" value="ASP.NET"/>  
        <http.header.info id="Cache-Control" value="private, max-age=0"/>  
    </http.header>  
    <DescargarFicheroPendienteResponse xmlns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
        <DescargarFicheroPendienteResult>  
            <NewDataSet xmlns="">  
                <Table1>  
                    <Nombre>0</Nombre>  
                    <Contenido/>  
                </Table1>  
            </NewDataSet>  
        </DescargarFicheroPendienteResult>  
    </DescargarFicheroPendienteResponse>  
</Payload>  

anyone can help me?

Thanks

Upvotes: 1

Views: 158

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

Given this in the XML:

<DescargarFicheroPendienteResponse xmlns="http://tempuri.org/" ....>  
    <DescargarFicheroPendienteResult>  
        <NewDataSet xmlns="">
            <Table1>  

an XPath expression

vpf:Payload[....]/DescargarFicheroPendienteResponse/
   DescargarFicheroPendienteResult/Table1/Nombre

will definitely not work - firstly, in the XML your DescargarFicheroPendienteResponse and DescargarFicheroPendienteResult elements are in the http://tempuri.org/ namespace so you will need to map that to a prefix in the stylesheet (e.g. xmlns:t="http://tempuri.org/") and then use that prefix in the XPath, and secondly there's a NewDataSet element above the Table1.

vpf:Payload[....]/t:DescargarFicheroPendienteResponse/
    t:DescargarFicheroPendienteResult/NewDataSet/Table1/Nombre

Upvotes: 1

Related Questions