xsl:template match for xml with prefixes
I have this xml file
<?xml version="1.0" encoding="UTF-8"?>
<bo:C837ClaimParent xsi:type="bo:C837ClaimParent"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bo="http://somelongpathHere/process/bo">
<claimAux>
...
</claimAux>
<enterpriseClaim>
...
<patientAccountNumber>data to capture here</patientAccountNumber>
</enterpriseClaim>
I need to match the data inside <patientAccountNumber>, which is inside <enterpriseClaim>, which is inside <bo:C837开发者_JAVA技巧ClaimParent> I have tried all the values I can think of on the xsl:template match and I cannot match that node, it either doesn't find it, or matches the entire xml file, my xsl file looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="2.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
....
<div>
<xsl:value-of select="C837ClaimParent/enterpriseClaim/patientAccountNumber" /></div>
what do I need to specify on my xsl:template and my xsl:value-of ?
also, for this same file I will be matching other values, everything is inside the main node <bo:C837ClaimParent, so what do I need to use so that I can efficiently match nodes throughout my file?
You seem to be missing a namespace declaration for your bo
prefix. This namespace will probably have to appear in your solution unless you use local-name()
edit (after namespace appeared!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bo="http://somelongpathHere/process/bo">
<xsl:output method="xml" version="2.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
....
<div>
<xsl:value-of select="bo:C837ClaimParent/enterpriseClaim/patientAccountNumber" /></div>
Are you sure that enterpriseClaim
is in a different namespace from C837ClaimParent
?
<xsl:stylesheet ... xmlns:bo="http://www.bo.org">
...
<xsl:value-of select="/bo:C837ClaimParent/enterpriseClaim/patientAccountNumber" />
...
</xsl:stylesheet>
In general, my advice would be to read up on namespaces in XML and XPath.
精彩评论