-2

This is my xml code:

 <define name="Procedure">
    <element name="Procedure" radlex:id="RID1559" radlex:match="Exact">
        <element name="View" radlex:id="RID10420" radlex:match="Exact">
            <optional>
                <element name="Supine" radlex:id="RID10421" radlex:match="Exact" snomed:id="416733000">
                    <empty/>
                </element>
            </optional>
            <optional>
                <element name="Upright" radlex:id="RID10455" radlex:match="Exact">
                    <empty/>
                </element>
            </optional>
            <text/>
        </element>
        <text/>
    </element>
</define>

I have written my XSLT code like this. Is this the correct way to write my code? Is this the correct way to use the if condition in XSLT?

Is it possible to code it like this:

Is it possible to read all tags (like element,optional,empty) by using a for each loop?

And if it is optional, then I want it to create a check box in HTML; I would like it to do it for all of them.

<xsl:template match="rng:define">
    <table>

    <xsl:for-each select="rng:element[@name='Procedure']">
      <span style="color:blue;">
        <tr>
          <td>
        <xsl:text> Procedure </xsl:text>
          </td>
        </tr>
        <xsl:if test="rng:element &gt; (rad:id='RID10420')">
          <tr>
              <td>
          <xsl:text> View </xsl:text>
              </td>
            </tr>
          <tr>
            <td>
              <input type="text" name="View"></input>
            </td>
          </tr> 
        </xsl:if>
        <xsl:if test="rng:element/rng:optional &gt; (rad:id='RID10421')">
          <tr>
            <td>
            <input text="Supine" name="cSupine" type="checkbox" class="checkbox" id="cSupine" value="checkbox"/>
              <xsl:text> Supine </xsl:text>
            </td>
          </tr>
        </xsl:if>
        <xsl:if test="rng:element/rng:optional &gt; (rad:id='RID10455')">
          <tr>
            <td>
            <input text="Upright" name="cUpright" type="checkbox" class="checkbox" id="cUpright" value="checkbox"/>
              <xsl:text> Upright </xsl:text>
            </td>
          </tr>
        </xsl:if>
       </span>
    </xsl:for-each>
    </table>
  </xsl:template>
Josh Ferrara
  • 757
  • 2
  • 9
  • 25

1 Answers1

2

A good way to understand how "we can code in XSLT" is to read a good book on XSLT, read any good answer in this tag, practice a little...

If you want just to have an impression of possible writing styles, do also have a look at the code of the FXSL library -- you would get a feeling of one particular coding style, which I believe isn't bad.

For example this code implements a generic, table-driven LR(1) parser in pure XSLT 2.0.

And this code calculates the maximum prime factor of 600851475143 (a pure XSLT solution to a nice project Euler problem).

You might also be interested to become acquainted with XPath, which is a most significant constituent of XSLT.

Here is a pure XPath implementation of a Binary Search Tree data type.

And here is a pure XPath implementation of a set type.

Finally, here is an XPath solution to the popular FizzBuzz problem.

Community
  • 1
  • 1
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431