Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSLT Output - blank attributes (http://www.velocityreviews.com/forums/t303847-xslt-output-blank-attributes.html)

requeth@gmail.com 06-29-2006 07:45 PM

XSLT Output - blank attributes
 
Allo,

I'm somewhat new to XSLT but I am doing fairly well. I just got stuck
on one item. I have created a XSL stylesheet to pull information from
an XML file and generate a report. I would like to add functionality
for missing data, in which if the attribute contains nothing ("") then
the field is red. I added in a choose function which flags it red, but
only if the attribute itself was not populated into the source file. Is
there a way to flag both if the attribute has not populated and if it
is just a blank attribute (""). If you know the answer to this, is
there a term for just "" that I could search more on?

Thanks


Joe Kesselman 06-30-2006 01:10 AM

Re: XSLT Output - blank attributes
 
requeth@gmail.com wrote:
> there a way to flag both if the attribute has not populated and if it
> is just a blank attribute ("")


First thought that occurs to me is string(@yourattribute)="", which
should be true for either case.

>is there a term for just ""


The most commonly used term is "empty string".

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry

requeth@gmail.com 06-30-2006 03:15 PM

Re: XSLT Output - blank attributes
 
I tried this, and looking around for information on the w3
recommendation and others. I add the string and nothing is changed. The
field will not populate in my output table at all if it is an empty
string. If I have any character, or no attribute in the file at all, it
flags red as I wish. I have attached what my origional code was, and
what I changed it to. I have tried many things to get this to work, but
as I said I'm fairly new to this.

<xsl:choose>
<xsl:when
test="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName
!= 0">
<td>
<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"/>
</td>
</xsl:when>
<xsl:otherwise>
<td bgcolor="RED"> </td>
</xsl:otherwise>
---------------------------

<xsl:choose>
<xsl:when
test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName)
!= 0">
<td>
<xsl:value-of

select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"
/>
</td>
</xsl:when>
<xsl:otherwise>
<td bgcolor="RED"> </td>
</xsl:otherwise>
Thanks

Joe Kesselman wrote:
> requeth@gmail.com wrote:
> > there a way to flag both if the attribute has not populated and if it
> > is just a blank attribute ("")

>
> First thought that occurs to me is string(@yourattribute)="", which
> should be true for either case.
>
> >is there a term for just ""

>
> The most commonly used term is "empty string".
>
> --
> () ASCII Ribbon Campaign | Joe Kesselman
> /\ Stamp out HTML e-mail! | System architexture and kinetic poetry



A. Bolmarcich 06-30-2006 04:16 PM

Re: XSLT Output - blank attributes
 
On 2006-06-30, requeth@gmail.com <requeth@gmail.com> wrote:
> I tried this, and looking around for information on the w3
> recommendation and others. I add the string and nothing is changed. The
> field will not populate in my output table at all if it is an empty
> string. If I have any character, or no attribute in the file at all, it
> flags red as I wish. I have attached what my origional code was, and
> what I changed it to. I have tried many things to get this to work, but
> as I said I'm fairly new to this.
>
><xsl:choose>
> <xsl:when
> test="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName
> != 0">


The "!= 0" comparison is false only when the attribute value is "0" (or
some other value that when converted to a number has a value of 0). The
comparison is true when the attribute is not present and when the
attribute has an empty value. Perhaps, you want to use something like

<xsl:test="string(...)">

where the "..." is your XPATH expression.

> <td>
> <xsl:value-of
> select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"/>
> </td>
> </xsl:when>
> <xsl:otherwise>
> <td bgcolor="RED"> </td>
> </xsl:otherwise>
> ---------------------------
>
><xsl:choose>
> <xsl:when
> test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName)
> != 0">
> <td>
> <xsl:value-of
>
> select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"
> />
> </td>
> </xsl:when>
> <xsl:otherwise>
> <td bgcolor="RED"> </td>
> </xsl:otherwise>


requeth@gmail.com 06-30-2006 05:49 PM

Re: XSLT Output - blank attributes
 
This is why I add the I'm an idiot explanations to posts. I had tried
this without the string expression but forgot to try it with it
included. That worked, thanks.

A. Bolmarcich wrote:
> On 2006-06-30, requeth@gmail.com <requeth@gmail.com> wrote:
> > I tried this, and looking around for information on the w3
> > recommendation and others. I add the string and nothing is changed. The
> > field will not populate in my output table at all if it is an empty
> > string. If I have any character, or no attribute in the file at all, it
> > flags red as I wish. I have attached what my origional code was, and
> > what I changed it to. I have tried many things to get this to work, but
> > as I said I'm fairly new to this.
> >
> ><xsl:choose>
> > <xsl:when
> > test="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName
> > != 0">

>
> The "!= 0" comparison is false only when the attribute value is "0" (or
> some other value that when converted to a number has a value of 0). The
> comparison is true when the attribute is not present and when the
> attribute has an empty value. Perhaps, you want to use something like
>
> <xsl:test="string(...)">
>
> where the "..." is your XPATH expression.
>
> > <td>
> > <xsl:value-of
> > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"/>
> > </td>
> > </xsl:when>
> > <xsl:otherwise>
> > <td bgcolor="RED"> </td>
> > </xsl:otherwise>
> > ---------------------------
> >
> ><xsl:choose>
> > <xsl:when
> > test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName)
> > != 0">
> > <td>
> > <xsl:value-of
> >
> > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"
> > />
> > </td>
> > </xsl:when>
> > <xsl:otherwise>
> > <td bgcolor="RED"> </td>
> > </xsl:otherwise>



Peter Flynn 07-03-2006 01:36 AM

Re: XSLT Output - blank attributes
 
requeth@gmail.com wrote:
> Allo,
>
> I'm somewhat new to XSLT but I am doing fairly well. I just got stuck
> on one item. I have created a XSL stylesheet to pull information from
> an XML file and generate a report. I would like to add functionality
> for missing data, in which if the attribute contains nothing ("") then
> the field is red. I added in a choose function which flags it red, but
> only if the attribute itself was not populated into the source file. Is
> there a way to flag both if the attribute has not populated and if it
> is just a blank attribute (""). If you know the answer to this, is
> there a term for just "" that I could search more on?


There may be more than presence or absence at work here.

If the DTD or Schema defines a default value for the attribute,
then the processor will behave as though the attribute was
specified with that value, even if it's physically absent from
the document.

<xsl:if test="@foo=''"> will only be true if
(a) foo="" is actually in the document, or
(b) the null string is declared as the default value

<xsl:if test="@foo"> will only be true if
(a) foo="" or foo="something" is actually in the document, or
(b) foo is declared with a default value (of any kind)

///Peter
--
XML FAQ: http://xml.silmaril.ie/


All times are GMT. The time now is 04:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.