473,396 Members | 1,849 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,396 software developers and data experts.

XSLT: How to avoid empty attributes in attribute-sets?

Hi!

I'm using xsl:attribute-sets to reduce redundancy in my XSLT.
An example from a transformation to XHTML (the attribute values are
simply copied from input to output):

<xsl:attribute-set name="cellhalign">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
<xsl:attribute name="char">
<xsl:value-of select="@char" />
</xsl:attribute>
<xsl:attribute name="charoff">
<xsl:value-of select="@charoff" />
</xsl:attribute>
</xsl:attribute-set>

Works fine, except that it generates empty attributes, if the attribute
is not defined in the source XML:

<td align="" char="" charoff="">31</td>

That's quite ugly. Especially when you have a lot of <td>'s...

Now you cannot use <xsl:ifin an <xsl:attribute-set>.
So if you like to create a "conditional attribute" you'd have to do it
within the template:

<xsl:template match="nitf:td">
<td>
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
</xsl:if>
<!-- repeat that for the other attrs -->
<xsl:apply-templates/>
</td>
</xsl:template>

But doing that will be extremely redundant if the same attributes apply
to several templates.

It there any solution to avoid redundant attribute declarations *and*
avoid empty attributes in the output XML?

Thank you very much!
Regards
--
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: st*********@jabber.i-pobox.net
GPG: 0xF534E231
Aug 26 '07 #1
0 1961

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

Similar topics

4
by: Eric Anderson | last post by:
I'm not sure if this is the correct place to post this question so please feel free to redirect me if needed. I am writing a XSL transform document to perform a transform on an XML document. I...
2
by: Jordan Willms | last post by:
Hi there. I am working with lom metadata and I am a little confused with how to form the following xml element: <lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2"...
2
by: Jon Martin Solaas | last post by:
Hi, I have a general document somewhat like this: -------------------------------------- <root> <level1> <level2> <interestingstuff number="2"/> <interestingstuff number="3"/>...
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 ...
1
by: Wayne Lian via .NET 247 | last post by:
Hi all, Just wonder anyone have encountered this problem before?I tried using XMLSPY debugger and I can get the correct outputfor my XSLT transformation, however in .net, aftertransformation the...
2
by: Fredrik Melin | last post by:
Hi, I have a vendor that requires me to send empty value, e.g. <OrderIDInfo /> problem is that my xslt need to add attributes, doing this <OrderIDInfo> <xsl:attribute name="orderID">...
4
by: David S. Alexander | last post by:
How can I do simple subtraction in an XSLT. I want to read a few attribute values from an XML document, calculate their difference, and transform that value to an attribute in the XML output...
3
by: Carles Company Soler | last post by:
Hello, I want to calculate the value of an attribute. For example <rect x="2+3" y="12"and be <rect x="5" y="12">. Is it possible using XSLT? Thanks!
11
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to a string then normalizing the strings. Then I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.