469,328 Members | 1,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

How to handle Missing Child Element

25
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
Jan 22 '08 #1
5 4019
jkmyoung
2,057 Expert 2GB
Not entirely sure what you're doing

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="unit">
  2.   <tr>
  3.     <td><xsl:value-of select="."/></td>
  4.     <xsl:variable name="lease">
  5.       <xsl:choose>
  6.         <xsl:when test="//lease[@ref = current()/@ref]"/>
  7.           <xsl:value-of select="//lease[@ref = current()/@ref]"/>
  8.         </xsl:when>
  9.         <xsl:otherwise>not found</xsl:otherwise>
  10.       </xsl:choose>
  11.      </xsl:variable>
  12.     <td><xsl:value-of select="$lease"/></td>
  13.   </tr>
  14. </xsl:template>
  15.  
Jan 22 '08 #2
rupak
25
Not entirely sure what you're doing

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="unit">
  2.   <tr>
  3.     <td><xsl:value-of select="."/></td>
  4.     <xsl:variable name="lease">
  5.       <xsl:choose>
  6.         <xsl:when test="//lease[@ref = current()/@ref]"/>
  7.           <xsl:value-of select="//lease[@ref = current()/@ref]"/>
  8.         </xsl:when>
  9.         <xsl:otherwise>not found</xsl:otherwise>
  10.       </xsl:choose>
  11.      </xsl:variable>
  12.     <td><xsl:value-of select="$lease"/></td>
  13.   </tr>
  14. </xsl:template>
  15.  

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
Jan 24 '08 #3
jkmyoung
2,057 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/">
  2.   <html>
  3.     <body>
  4.       <xsl:apply-templates select="//unit"/>
  5.     </body>
  6.   </html>
  7. </xsl:template>
  8.  
Jan 24 '08 #4
rupak
25
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.
Mar 28 '08 #5
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>

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



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
Mar 31 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by Harlan Messinger | last post: by
7 posts views Thread by Markus Ernst | last post: by
reply views Thread by Alberto Grosso Nicolin | last post: by
2 posts views Thread by Paulers | last post: by
5 posts views Thread by mareeus | last post: by
3 posts views Thread by Marcolino | last post: by
2 posts views Thread by Claudia Fong | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.