How to get XSL to ignore xmlns prefix when testing an XML element

veitustyequiz

New Member
I have created a client that talks to web services on various servers, and am trying to format the XML using XSL. The services were all created from the same specification, so the XML they emit has the same format and xmlns namespace names. My XSL needs to test the elements for specific types to know how to format them. The problem is that between the servers, they are using different xmlns prefixes. The test I have been using is a pure string comparison and does not expand the prefix into the full xmlns, so the comparisons are failing. My question is, is there a way to expand the prefix so that a string compare works? This is a simplified example to illustrate the problem. In the "xsl:if test" lines, I need to expand the "r0" and "xx" into "http://www.foo.com/2.1/schema" so that they test the same:XSL:\[code\]<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:r0="http://www.foo.com/2.1/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsl:template match="/"><html><head> </head> <body > <xsl:for-each select="MyResp/r0:creditVendReceipt/r0:transactions/r0:tx"> <xsl:if test="@xsi:type='r0:CreditTx'"> <xsl:value-of select="r0:amt/@value"/>(CR) </xsl:if> <xsl:if test="@xsi:type='r0:DebitTx'"> <xsl:value-of select="r0:amt/@value"/>(DB) </xsl:if> </xsl:for-each> </body> </html> </xsl:template></xsl:stylesheet>\[/code\]XML (this works):\[code\]<?xml version="1.0" encoding="unicode"?><MyResp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:r0="http://www.foo.com/2.1/schema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><r0:creditVendReceipt receiptNo="1234567890"> <r0:transactions> <r0:tx xsi:type="r0:CreditTx"> <r0:amt value="http://stackoverflow.com/questions/15548544/100" /> </r0:tx> <r0:tx xsi:type="r0:DebitTx"> <r0:amt value="http://stackoverflow.com/questions/15548544/50" /> </r0:tx> </r0:transactions></r0:creditVendReceipt></MyResp>\[/code\]XML (this fails):\[code\]<?xml version="1.0" encoding="unicode"?><MyResp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xx="http://www.foo.com/2.1/schema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><xx:creditVendReceipt receiptNo="1234567890"> <xx:transactions> <xx:tx xsi:type="xx:CreditTx"> <xx:amt value="http://stackoverflow.com/questions/15548544/100" /> </xx:tx> <xx:tx xsi:type="xx:DebitTx"> <xx:amt value="http://stackoverflow.com/questions/15548544/50" /> </xx:tx> </xx:transactions></xx:creditVendReceipt></MyResp>\[/code\]
 
Back
Top