Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 15 Jan 2008 15:15:01 -0800,    group: microsoft.public.xsl        back       


Using xsl:if with xsl:value-of   
I am using an open source HTML editor in an ASP.NET project to permit the 
users to create templates for form letters.  When the user chooses to save 
the current template, I parse the HTML to create the XSL for populating the 
letters and I write both the HTML and XSL to the database.  Among the things 
the user can do is incorporate a table in the form letter, inserting both 
text and data in the table.  To maintain borders around those cells that are 
intentionally left empty in design mode, I replace the "<td> </td>" HTML 
string with "<td><xsl:text 
disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since XSL 
doesn't seem to like " ".

The above works like a charm as long as there is data for all fields within 
the table; if data for one field is missing, the border for that cell doesn't 
match the borders of all the other cells in the table.  So my question is 
this: how can I go about using data in the cell if any is available or 
replacing it with the disable-output-escaping statement as shown above?  I 
thought there might be a way of incorporating xsl:if along with xsl:value-of, 
but I honestly don't know.  Anyway...

A portion of the XML I'm reading is as follows:
<entity>
    <ProviderID>12345</ProviderID>
    <ProviderName>Butcher Burns, MD</ProviderName>
    <ClaimNumber>1Z3ED0999</ClaimNumber>
    <DateOfService>12/01/2005</DateOfService>
</entity>
<entity>
    <ProviderID>12346</ProviderID>
    <ProviderName>Blades Messina, MD</ProviderName>
    <ClaimNumber>1Z3EF0000</ClaimNumber>
    <DateOfService></DateOfService>
</entity>

A portion of the currently-existing XSL is listed below.  The entire table 
containing the following snippet is inside an xsl:for-each loop.
<tr>
   <td align="right">Claim Number:</td>
   <td><xsl:value-of select="ClaimNumber" /></td>
   <td align="right">Date of Service:</td>
   <td><xsl:value-of select="DateOfService" /></td>
</tr>

In this case, I want the fourth cell to contain the Date of Service the 
first time through the loop since the data is provided for that iteration.  
On the second iteration, the fourth cell needs to contain "<td><xsl:text 
disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since Date of 
Service data isn't provided for it.


-- 
Things are more like they are now than they ever have been before.
date: Tue, 15 Jan 2008 15:15:01 -0800   author:   AlBruAn .(donotspam)

Re: Using xsl:if with xsl:value-of   
You can use   instead of   in XML

  is the decimal code for a non-breaking space, which is
identical to the   entity (that is only defined by HTML DTD)

There's no need to invoke CDATA and escaping here.

If you do have problems with the input HTML parsing correctly, run the
content through "Tidy" which has bindings for a range of languages
including .NET : See http://tidy.sourceforge.net/ and this page for
.NET specfic : http://users.rcn.com/creitzel/tidy.html#dotnet

The default settings are almost always fine for general use.

HTH
Cheers - Neil

On Tue, 15 Jan 2008 15:15:01 -0800, AlBruAn
<albruan@hotmail.com.(donotspam)> wrote:

>I am using an open source HTML editor in an ASP.NET project to permit the 
>users to create templates for form letters.  When the user chooses to save 
>the current template, I parse the HTML to create the XSL for populating the 
>letters and I write both the HTML and XSL to the database.  Among the things 
>the user can do is incorporate a table in the form letter, inserting both 
>text and data in the table.  To maintain borders around those cells that are 
>intentionally left empty in design mode, I replace the "<td> </td>" HTML 
>string with "<td><xsl:text 
>disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since XSL 
>doesn't seem to like " ".
>
>The above works like a charm as long as there is data for all fields within 
>the table; if data for one field is missing, the border for that cell doesn't 
>match the borders of all the other cells in the table.  So my question is 
>this: how can I go about using data in the cell if any is available or 
>replacing it with the disable-output-escaping statement as shown above?  I 
>thought there might be a way of incorporating xsl:if along with xsl:value-of, 
>but I honestly don't know.  Anyway...
>
>A portion of the XML I'm reading is as follows:
><entity>
>    <ProviderID>12345</ProviderID>
>    <ProviderName>Butcher Burns, MD</ProviderName>
>    <ClaimNumber>1Z3ED0999</ClaimNumber>
>    <DateOfService>12/01/2005</DateOfService>
></entity>
><entity>
>    <ProviderID>12346</ProviderID>
>    <ProviderName>Blades Messina, MD</ProviderName>
>    <ClaimNumber>1Z3EF0000</ClaimNumber>
>    <DateOfService></DateOfService>
></entity>
>
>A portion of the currently-existing XSL is listed below.  The entire table 
>containing the following snippet is inside an xsl:for-each loop.
><tr>
>   <td align="right">Claim Number:</td>
>   <td><xsl:value-of select="ClaimNumber" /></td>
>   <td align="right">Date of Service:</td>
>   <td><xsl:value-of select="DateOfService" /></td>
></tr>
>
>In this case, I want the fourth cell to contain the Date of Service the 
>first time through the loop since the data is provided for that iteration.  
>On the second iteration, the fourth cell needs to contain "<td><xsl:text 
>disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since Date of 
>Service data isn't provided for it.
------------------------------------------------
Digital Media MVP : 2004-2008
http://mvp.support.microsoft.com/mvpfaqs
date: Wed, 16 Jan 2008 00:03:44 GMT   author:   Neil Smith [MVP Digital Media]

Re: Using xsl:if with xsl:value-of   
Thank you for suggesting a way of avoiding using CDATA and escaping the &.  
My question is still this: how can I go about using data in the cell if any 
is available or replacing it, as you've suggested, with the   to ensure 
the border is drawn around the cell?  As I mentioned in my original post, I 
thought there might be a way of incorporating xsl:if along with xsl:value-of, 
but I honestly don't know.
-- 
Things are more like they are now than they ever have been before.


"Neil Smith [MVP Digital Media]" wrote:

> You can use   instead of   in XML
> 
>   is the decimal code for a non-breaking space, which is
> identical to the   entity (that is only defined by HTML DTD)
> 
> There's no need to invoke CDATA and escaping here.
> 
> If you do have problems with the input HTML parsing correctly, run the
> content through "Tidy" which has bindings for a range of languages
> including .NET : See http://tidy.sourceforge.net/ and this page for
> ..NET specfic : http://users.rcn.com/creitzel/tidy.html#dotnet
> 
> The default settings are almost always fine for general use.
> 
> HTH
> Cheers - Neil
> 
> On Tue, 15 Jan 2008 15:15:01 -0800, AlBruAn
> <albruan@hotmail.com.(donotspam)> wrote:
> 
> >I am using an open source HTML editor in an ASP.NET project to permit the 
> >users to create templates for form letters.  When the user chooses to save 
> >the current template, I parse the HTML to create the XSL for populating the 
> >letters and I write both the HTML and XSL to the database.  Among the things 
> >the user can do is incorporate a table in the form letter, inserting both 
> >text and data in the table.  To maintain borders around those cells that are 
> >intentionally left empty in design mode, I replace the "<td> </td>" HTML 
> >string with "<td><xsl:text 
> >disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since XSL 
> >doesn't seem to like " ".
> >
> >The above works like a charm as long as there is data for all fields within 
> >the table; if data for one field is missing, the border for that cell doesn't 
> >match the borders of all the other cells in the table.  So my question is 
> >this: how can I go about using data in the cell if any is available or 
> >replacing it with the disable-output-escaping statement as shown above?  I 
> >thought there might be a way of incorporating xsl:if along with xsl:value-of, 
> >but I honestly don't know.  Anyway...
> >
> >A portion of the XML I'm reading is as follows:
> ><entity>
> >    <ProviderID>12345</ProviderID>
> >    <ProviderName>Butcher Burns, MD</ProviderName>
> >    <ClaimNumber>1Z3ED0999</ClaimNumber>
> >    <DateOfService>12/01/2005</DateOfService>
> ></entity>
> ><entity>
> >    <ProviderID>12346</ProviderID>
> >    <ProviderName>Blades Messina, MD</ProviderName>
> >    <ClaimNumber>1Z3EF0000</ClaimNumber>
> >    <DateOfService></DateOfService>
> ></entity>
> >
> >A portion of the currently-existing XSL is listed below.  The entire table 
> >containing the following snippet is inside an xsl:for-each loop.
> ><tr>
> >   <td align="right">Claim Number:</td>
> >   <td><xsl:value-of select="ClaimNumber" /></td>
> >   <td align="right">Date of Service:</td>
> >   <td><xsl:value-of select="DateOfService" /></td>
> ></tr>
> >
> >In this case, I want the fourth cell to contain the Date of Service the 
> >first time through the loop since the data is provided for that iteration.  
> >On the second iteration, the fourth cell needs to contain "<td><xsl:text 
> >disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since Date of 
> >Service data isn't provided for it.
> ------------------------------------------------
> Digital Media MVP : 2004-2008
> http://mvp.support.microsoft.com/mvpfaqs
>
date: Wed, 16 Jan 2008 05:59:00 -0800   author:   AlBruAn .(donotspam)

RE: Using xsl:if with xsl:value-of   
I finally figure it out using a combination of xsl:choose, xsl:when and 
xsl:otherwise in conjunction with the xsl:value-of statements.  Thanks again 
for your suggestion on replacing the CDATA string with &160, Neil; it makes 
for much cleaner code.
-- 
Things are more like they are now than they ever have been before.


"AlBruAn" wrote:

> I am using an open source HTML editor in an ASP.NET project to permit the 
> users to create templates for form letters.  When the user chooses to save 
> the current template, I parse the HTML to create the XSL for populating the 
> letters and I write both the HTML and XSL to the database.  Among the things 
> the user can do is incorporate a table in the form letter, inserting both 
> text and data in the table.  To maintain borders around those cells that are 
> intentionally left empty in design mode, I replace the "<td> </td>" HTML 
> string with "<td><xsl:text 
> disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since XSL 
> doesn't seem to like " ".
> 
> The above works like a charm as long as there is data for all fields within 
> the table; if data for one field is missing, the border for that cell doesn't 
> match the borders of all the other cells in the table.  So my question is 
> this: how can I go about using data in the cell if any is available or 
> replacing it with the disable-output-escaping statement as shown above?  I 
> thought there might be a way of incorporating xsl:if along with xsl:value-of, 
> but I honestly don't know.  Anyway...
> 
> A portion of the XML I'm reading is as follows:
> <entity>
>     <ProviderID>12345</ProviderID>
>     <ProviderName>Butcher Burns, MD</ProviderName>
>     <ClaimNumber>1Z3ED0999</ClaimNumber>
>     <DateOfService>12/01/2005</DateOfService>
> </entity>
> <entity>
>     <ProviderID>12346</ProviderID>
>     <ProviderName>Blades Messina, MD</ProviderName>
>     <ClaimNumber>1Z3EF0000</ClaimNumber>
>     <DateOfService></DateOfService>
> </entity>
> 
> A portion of the currently-existing XSL is listed below.  The entire table 
> containing the following snippet is inside an xsl:for-each loop.
> <tr>
>    <td align="right">Claim Number:</td>
>    <td><xsl:value-of select="ClaimNumber" /></td>
>    <td align="right">Date of Service:</td>
>    <td><xsl:value-of select="DateOfService" /></td>
> </tr>
> 
> In this case, I want the fourth cell to contain the Date of Service the 
> first time through the loop since the data is provided for that iteration.  
> On the second iteration, the fourth cell needs to contain "<td><xsl:text 
> disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></td>" since Date of 
> Service data isn't provided for it.
> 
> 
> -- 
> Things are more like they are now than they ever have been before.
date: Wed, 16 Jan 2008 06:26:01 -0800   author:   AlBruAn .(donotspam)

Re: Using xsl:if with xsl:value-of   
AlBruAn wrote:
> Thank you for suggesting a way of avoiding using CDATA and escaping the &.  
> My question is still this: how can I go about using data in the cell if any 
> is available or replacing it, as you've suggested, with the   to ensure 
> the border is drawn around the cell?  As I mentioned in my original post, I 
> thought there might be a way of incorporating xsl:if along with xsl:value-of, 
> but I honestly don't know.

Use xsl:choose e.g. replace

<td><xsl:value-of select="ClaimNumber" /></td>

with

<td>
   <xsl:choose>
     <xsl:when test="normalize-space(ClaimNumber)">
       <xsl:value-of select="ClaimNumber"/>
     <xsl:when>
     <xsl:otherwise> </xsl:otherwise>
   </xsl:choose>
</td>

If you are using XSLT 2.0 then it is even easier
<td><xsl:value-of select="if (normalize-space(ClaimNumber)) then 
ClaimNumber else ' '"/></td>

You should also investigate CSS 2 and the setting empty-cells: show. If 
your browser supports that (and Mozilla, Opera do) then you can avoid 
the above attempts and simply use CSS to ensure that empty cells are 
shown: <URL:http://www.w3.org/TR/CSS21/tables.html#empty-cells>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Wed, 16 Jan 2008 15:28:53 +0100   author:   Martin Honnen

Re: Using xsl:if with xsl:value-of   
Martin, thanks for the suggestions.  I finally figured out how to use 
xsl:choose, xsl:when, and xsl:otherwise to accomplish my task just about ten 
minutes before your posting.  I wanted to try using XSLT 2.0 as you 
suggested, but I'm working in a corporate environment where it isn't being 
utilized.  I also tried adding empty-cells:show to the table's style 
attribute, but it also appeared not to be supported here.  Anyway, thanks 
again for your suggestions.

Allen Anderson
-- 
Things are more like they are now than they ever have been before.


"Martin Honnen" wrote:

> AlBruAn wrote:
> > Thank you for suggesting a way of avoiding using CDATA and escaping the &.  
> > My question is still this: how can I go about using data in the cell if any 
> > is available or replacing it, as you've suggested, with the   to ensure 
> > the border is drawn around the cell?  As I mentioned in my original post, I 
> > thought there might be a way of incorporating xsl:if along with xsl:value-of, 
> > but I honestly don't know.
> 
> Use xsl:choose e.g. replace
> 
> <td><xsl:value-of select="ClaimNumber" /></td>
> 
> with
> 
> <td>
>    <xsl:choose>
>      <xsl:when test="normalize-space(ClaimNumber)">
>        <xsl:value-of select="ClaimNumber"/>
>      <xsl:when>
>      <xsl:otherwise> </xsl:otherwise>
>    </xsl:choose>
> </td>
> 
> If you are using XSLT 2.0 then it is even easier
> <td><xsl:value-of select="if (normalize-space(ClaimNumber)) then 
> ClaimNumber else ' '"/></td>
> 
> You should also investigate CSS 2 and the setting empty-cells: show. If 
> your browser supports that (and Mozilla, Opera do) then you can avoid 
> the above attempts and simply use CSS to ensure that empty cells are 
> shown: <URL:http://www.w3.org/TR/CSS21/tables.html#empty-cells>
> 
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
>
date: Thu, 17 Jan 2008 13:36:05 -0800   author:   AlBruAn .(donotspam)

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us