0

I'm doing my school project that had us make an xsl transformation where we use for-each but i cant find mistake i made in it.

I already tried changing name of dtb_Items, changing xsl:template match="/" to match "dtb_Items/Item/" tried more different approach by changing the way in different manner which was wrong in elementary things.

<dtb_Items>
  <Item id="1">
    <name>Iron Gloves</name>
    <rarity>Uncommon</rarity>
    <stats>
      <s_str type="boost">7</s_str>
      <s_dex type="nerf">1</s_dex>
      <s_con type="none"></s_con>
      <s_int type="none"></s_int>
      <s_wis type="none"></s_wis>
      <s_cha type="none"></s_cha>
    </stats>
    <group>Equip - Gloves</group>
  </Item>
</dtb_Items>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <h2>Items design</h2>
        <table border="1">
          <tr bgcolor="">
            <th>Name</th>
            <th>Rarity</th>
            <th>strenght</th>
            <th>group</th>
          </tr>
          <xsl:for-each select="dtb_Items/Item">
            <tr>
              <td><xsl:value-of select="name"/></td>
              <td><xsl:value-of select="rarity"/></td>
              <td><xsl:value-of select="stats/s_str"/></td>
              <td><xsl:value-of select="group"/></td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

I expect to be able to see every line that is in xml instead of none

  • Your XML has undefined entities `&Uncommon;` `&Equip;` and `&Gloves;`. -- P.S. Please do not post partial code - see: [mcve]. – michael.hor257k Apr 26 '19 at 17:38
  • Edited sorry for inconvenience entities are replaced (they work fine in original code) with plain text – Pavel Maček Apr 26 '19 at 17:51
  • So how do you run the XSLT code, how does the output look exactly? That code looks fine and does produce some HTML output. Not sure what you consider a "line" in XML and which output you want and which one you got. So either your input is different (namespace?) or your tool (you haven't said which one you use to run the XSLT) is not applying the XSLT correctly. At https://xsltfiddle.liberty-development.net/bFN1y9w I have used your samples and added ``, both the raw HTML output as well as the display of the HTML look fine. – Martin Honnen Apr 26 '19 at 18:21
  • [xsltfiddle](https://xsltfiddle.liberty-development.net/bFN1y9w/5) this is the full version of what i am trying to complete here you can see the rows dont generate as in this shortened exmple – Pavel Maček Apr 26 '19 at 18:41
  • @PavelMaček Your XML is in a *namespace* - see: https://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k Apr 26 '19 at 18:54

1 Answers1

0

A classic: you posted simplified code that excludes the namespace declaration (xmlns="...") which is the thing that stops your code working.

Search for "XSLT default namespace" to find hundreds of other people who have fallen into the same trap, and have been helped out of it.

This will probably be closed as a duplicate. (Q: my stylesheet doesn't work. A: your source document is in a namespace).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164