views:

187

answers:

2

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"&gt;
<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:C837ClaimParent> 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"&gt;
    <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?

+2  A: 

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"&gt;
    <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?

peter.murray.rust
you're right, I just added it
BlackTigerX
sorry, I fixed the formatting problems, had many problems getting it right on the editor
BlackTigerX
that did it, adding the namespace, now how do I avoid having to specify that prefix on every single select, is that efficient?
BlackTigerX
You cannot avoid the prefix. In XML, it's possible to have a default namespace (with no prefix), but in XPath, no prefix always means empty namespace (i.e. with no URI). This does not affect efficiency in any way.
Pavel Minaev
+1  A: 
<xsl:stylesheet ... xmlns:bo="http://www.bo.org"&gt;
   ...
   <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.

Pavel Minaev
I have tried that already, I get this error: "Reference to undeclared namespace prefix: 'bo'"
BlackTigerX
Please note the `xmlns:bo` declaration on `<xsl:stylesheet>`!
Pavel Minaev
@Pavel note he has added a different namespace for bo from yours
peter.murray.rust
thanks Pavel, that was part of the issue
BlackTigerX