How to remove empty attributes?

Get help developing custom BBCodes or request one.
Post Reply
au@
Registered User
Posts: 4
Joined: Thu Nov 19, 2015 4:30 pm

How to remove empty attributes?

Post by au@ »

I've got 2 optional attributes:

Code: Select all

[td colspan={NUMBER1;optional} rowspan={NUMBER2;optional}]{TEXT}[/td]

Code: Select all

<td colspan="{NUMBER1}" rowspan="{NUMBER2}">{TEXT}</td>
Is there a best way to remove empty attributes from html result? (Clean <td> without colspan and rowspan strings if they are null).
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: How to remove empty attributes?

Post by JoshyPHP »

You can use XSLT to only add an attribute if it's specified.

Code: Select all

<td>
	<xsl:copy-of select="@colspan"/>
	<xsl:copy-of select="@rowspan"/>
	<xsl:apply-templates/>
</td>
I wrote the library that handles markup in phpBB 3.2+.
au@
Registered User
Posts: 4
Joined: Thu Nov 19, 2015 4:30 pm

Re: How to remove empty attributes?

Post by au@ »

JoshyPHP wrote: Fri Oct 05, 2018 8:30 pm You can use XSLT to only add an attribute if it's specified.
Thank you for your help!
You're the best! )
Post Reply

Return to “Custom BBCode Development and Requests”