xml 2 html sau formatarea unui raspuns web service

Si-am dat de o problema: namespace-urile.

In incercarea disperata de a transforma cu un xslt raspunsul unui web service si dupa vreo ora de rateuri am realizat ca de fapt namespace-ul definit pentru web service era vinovatul.

Si un mic exemplu:
Raspunsul web service-ului

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xsl" href="customer.xsl" ?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCustomerResponse xmlns="http://www.company.com/webservice/">

<Customer>
<Address>
<Street>Pictor Grigorescu</Street>
<StreetNo>2</StreetNo>
</Address>
</Customer>

</GetCustomerResponse>
</soap:Body>
</soap:Envelope>


Acu si xslu



<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

<!-- aici definesc namespace-ul web serviceului -->
<!-- cand construiesc XPath-uri folosesc prefixul ws -->

xmlns:ws="http://www.company.com/webservice/"
exclude-result-prefixes="soap"
version="1.0">

<xsl:output
method="html"
version="1.0"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent="yes"/>


<xsl:template match="/soap:Envelope/soap:Body/ws:GetCustomerResponse/ws:Customer">

<html>
<head>
<title>Customer info</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>

<xsl:apply-templates select="ws:Address"/>

</body>
</html>
</xsl:template>

<xsl:template match="ws:Address">
<p>Street: <xsl:value-of select="./ws:Street"/></p>
<p>Street Number: <xsl:value-of select="./ws:StreetNo"/></p>
</xsl:template>
</xsl:stylesheet>

Comments

Popular posts from this blog

IIS 7.5, HTTPS Bindings and ERR_CONNECTION_RESET

Table Per Hierarchy Inheritance with Column Discriminator and Associations used in Derived Entity Types

Verify ILogger calls with Moq.ILogger