How to handle Missing Child Element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rupak
    New Member
    • Jan 2008
    • 25

    How to handle Missing Child Element

    I have an XML want and output in HTML so using and XSL for that. The XML file i am using

    <property ref="1">
    <units>
    <unit ref="1">first floor</unit>
    <unit ref="2">second floor</unit>
    <unit ref="3">third floor</unit>
    <unit ref="4">fourth floor</unit>
    </units>
    <leases>
    <lease ref="1">OPEN</lease>
    <lease ref="2">CLOSE</lease>
    <lease ref="3">OPEN</lease>
    </leases>
    </property>

    I want to find out the HTML output where the property unit compared with lease. Facing problem when unit ref="4" but dont find out lease with same ref so want a text against that
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Not entirely sure what you're doing

    [code=xml]
    <xsl:template match="unit">
    <tr>
    <td><xsl:valu e-of select="."/></td>
    <xsl:variable name="lease">
    <xsl:choose>
    <xsl:when test="//lease[@ref = current()/@ref]"/>
    <xsl:value-of select="//lease[@ref = current()/@ref]"/>
    </xsl:when>
    <xsl:otherwise> not found</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <td><xsl:valu e-of select="$lease"/></td>
    </tr>
    </xsl:template>
    [/code]

    Comment

    • rupak
      New Member
      • Jan 2008
      • 25

      #3
      Originally posted by jkmyoung
      Not entirely sure what you're doing

      [code=xml]
      <xsl:template match="unit">
      <tr>
      <td><xsl:valu e-of select="."/></td>
      <xsl:variable name="lease">
      <xsl:choose>
      <xsl:when test="//lease[@ref = current()/@ref]"/>
      <xsl:value-of select="//lease[@ref = current()/@ref]"/>
      </xsl:when>
      <xsl:otherwise> not found</xsl:otherwise>
      </xsl:choose>
      </xsl:variable>
      <td><xsl:valu e-of select="$lease"/></td>
      </tr>
      </xsl:template>
      [/code]

      Thanks for the reply, i tried it but it is giving the output that i want and looking for but also and extra values of lease i.e.

      first floor OPEN
      second floor CLOSE
      third floor OPEN
      fourth floor not found
      OPENCLOSEOPEN

      I want to remove last line

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        [code=xml]
        <xsl:template match="/">
        <html>
        <body>
        <xsl:apply-templates select="//unit"/>
        </body>
        </html>
        </xsl:template>
        [/code]

        Comment

        • rupak
          New Member
          • Jan 2008
          • 25

          #5
          Originally posted by rupak
          Thanks for the reply, i tried it but it is giving the output that i want and looking for but also and extra values of lease i.e.

          first floor OPEN
          second floor CLOSE
          third floor OPEN
          fourth floor not found
          OPENCLOSEOPEN

          I want to remove last line

          You have helped me with removing the last line, thanks for the help.

          Now my requirement has changed bit further.

          Presently my O/p is as below:

          first floor OPEN
          second floor CLOSE
          third floor OPEN
          fourth floor not found

          Now I want to show O/p:

          first floor OPEN

          with
          Prev. & Next Button
          On click of them will move to

          second floor CLOSE

          with
          Prev. & Next Button
          On click of them will move to

          third floor OPEN

          Simillarly till the last record.

          Comment

          • saran3b2
            New Member
            • Aug 2007
            • 19

            #6
            I can't understand ur problem clearly. But try like this

            <xsl:if text="unit[@ref]">
            <xsl:value-of select="@ref"/>
            </xsl:if>

            <xsl:if text="lease[@ref]">
            <xsl:value-of select="@ref"/>
            </xsl:if>

            -----------------------------------------------------------------------------------------------------



            Originally posted by rupak
            I have an XML want and output in HTML so using and XSL for that. The XML file i am using

            <property ref="1">
            <units>
            <unit ref="1">first floor</unit>
            <unit ref="2">second floor</unit>
            <unit ref="3">third floor</unit>
            <unit ref="4">fourth floor</unit>
            </units>
            <leases>
            <lease ref="1">OPEN</lease>
            <lease ref="2">CLOSE</lease>
            <lease ref="3">OPEN</lease>
            </leases>
            </property>

            I want to find out the HTML output where the property unit compared with lease. Facing problem when unit ref="4" but dont find out lease with same ref so want a text against that

            Comment

            Working...