473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

Jun 29 '06 #1
5 1396
re*****@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
Jun 30 '06 #2
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:
re*****@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


Jun 30 '06 #3
On 2006-06-30, re*****@gmail.com <re*****@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>

Jun 30 '06 #4
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, re*****@gmail.com <re*****@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>


Jun 30 '06 #5
re*****@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/
Jul 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin | last post by:
Hallo, can you help me writing a generic xslt transformation (useable with xsql from oracle)? The problem is how to get the escaping characters .... === INPUT-File in.xml <?xml version =...
1
by: Wolfgang | last post by:
XSLT transformations by default seem to pass name space attributes into the root element of their output (example below). QUESTION: Is it possible to control this, i.e. not genrating a name...
3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
3
by: Alex | last post by:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net framework XSLT processor. The intent was to just copy the entities...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
2
by: Stefan | last post by:
Hi there! I'm very new to XML and XSLT, so while working i encountered the following, probably very easy to solve, problem. i've got 2 XML-files, which look like this: LinesOfCode.xml:...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
1
by: Bilal Bhutta | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
1
by: kbozek | last post by:
I have an XSLT transform that will create an XML to XML transformation in the parent child format. I really want to output the elements and attributes on a single line such as: <image...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.