XSLT Output - blank attributes

R

requeth

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
 
J

Joe Kesselman

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".
 
R

requeth

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_ProviderLastOrOrganizationName
!= 0">
<td>
<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"/>
</td>
</xsl:when>
<xsl:eek:therwise>
<td bgcolor="RED"> </td>
</xsl:eek:therwise>
---------------------------

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

select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"
/>
</td>
</xsl:when>
<xsl:eek:therwise>
<td bgcolor="RED"> </td>
</xsl:eek:therwise>
Thanks
 
A

A. Bolmarcich

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_ProviderLastOrOrganizationName
!= 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.
 
R

requeth

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.
 
P

Peter Flynn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top