0

Thanks to this board for assistance with a prior related post.

Apologies for what I am sure are the most basic questions regarding XML. I am a newbie for XML.

My XSL works properly if I remove all the attributes from the DataContext node at the top of the tree.

The minute I add them back into the node, my XSL stops displaying values in the output.

Through a bit of research I see the xmlns is actually a reserved attribute. I have done a bit of reading but still don't quite understand why it is having this result.

Here is my XSL:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>My Text XSL</h2>
    <table border="1">
      <tr>
        <th>attr9</th>
      </tr>
      <xsl:for-each select="/DCXT/ATRs/ATR">
        <tr>
          <td><xsl:value-of select="@attr9"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Here is my XML with the names changed to protect the innocent.

Specific issue is in the topmost node, the DCXT node.

(carriage returns put in for your convenience, they do not exist in the actual xml

<DCXT xmlns="http://www.xxxx.c0m" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" contactPerson="xxxx" ourId="xxxx" version="xxxx" dbPrefix="xxx" 
xsi:schemaLocation="http://www.xxx.c0m/a/b/yyyy-dd filename_aa.bb.cc.xsd">

    <Desc>Text description</Desc>
    <dbc>
        <drv>text for drv</drv>
        <prm/>
        <hsNode>text for hsNode</hsNode>
        <ptNode>text for ptNode</ptNode>
        <sName>text for sname</sName>
        <prd/>
    </dbc>
    <DSPs attr4="aaaa" attr5="1" attr3="bbb">
        <dsp attr6="1" attr7="true" attr8="1">
            <Desc>text for desc</Desc>
        </dsp>
        <!--... multiple 'Dsp' nodes defined defined ...-->
    </DSPs>
    <ATRs>
        <ATR attr9="true" attr10="text for attr">
            <FRs>
                <FR attr11="xxx" attr12="text for attr">
                    <MPs>
                        <MP attr13="xxx" attr14="yyyy"/>
                        <!-- .... multiple MP nodes defined -->
                    </MPs>
                </FR>
                <!--... multiple FR nodes defined ...-->
            </FRs>
            <DPY>
                <RDFs>
                    <SOF attr15="xxx" attr16="0"/>
                </RDFs>
                <BFRs>
                    <sof attr17="xxx" attr18="0"/>
                </BFRs>
            </DPY>
        </ATR>
        <!-- multiple ATR nodes defined -->
    </ATRs>
    <!-- more nodes defined at this level but removing for brevity-->
</DCXT>
Don
  • 43
  • 6
  • 1
    `xmlns="..."` is not an attribute, it's a namespace declaration. See: http://stackoverflow.com/a/29840370/3016153 and http://stackoverflow.com/questions/22590320/not-getting-data-to-transform-xml/22590777#22590777 and http://stackoverflow.com/questions/24086520/selecting-matching-elements-in-a-namespace/24086688#24086688 and many more... – michael.hor257k Apr 24 '15 at 20:20
  • In fact, type "XSLT default namespace" into the search box, and you will find 450 people who have asked the same question. The trouble is, many of them like you have failed to study the basic concepts before launching into coding, so they don't know how to phrase the question. – Michael Kay Apr 24 '15 at 21:03

0 Answers0