xsl code help for BBCode please

Get help developing custom BBCodes or request one.
Post Reply
WainPetopia
Registered User
Posts: 11
Joined: Thu Jul 18, 2019 5:55 am

xsl code help for BBCode please

Post by WainPetopia » Wed Sep 04, 2019 8:15 am

Since upgrading our board to 3.2 I've been struggling to get our custom BBCodes working with xsl. By searching the boards and looking at solutions given to others I have most of them working now, but there are still a few things I don't understand. The major one for me right now is our code for a html anchor:

Code: Select all

[anchor={SIMPLETEXT1?}]{SIMPLETEXT2}[/anchor]


My code for it is:

Code: Select all

<xsl:choose>
    <xsl:when test="@anchor">
      <span id="{SIMPLETEXT1}">{SIMPLETEXT2}</span>
    </xsl:when>
    <xsl:otherwise>
        <span id="{SIMPLETEXT2}"></span>
    </xsl:otherwise>
</xsl:choose>
This works fine for the two most obvious cases:
  • Code: Select all

    [anchor=anchortext]Visible text[/anchor]
    results in "Visible text", wrapped in the anchor/id "anchortext"
  • Code: Select all

    [anchor]anchortext[/anchor]
    results in an invisible anchor with the id "anchortext"
But if someone types:

Code: Select all

[anchor=anchortext][/anchor]
(i.e. no {SIMPLETEXT2}) I want it to also create an invisible anchor. Instead it seems to freak out about the fact that {SIMPLETEXT2} wasn't supplied and it instead prints out the BBCode as visible text.

So, in the xsl how do I check if {SIMPLETEXT2} doesn't exist and not use it?

Also, is there any official documentation on this site on how to use xsl with BBCodes? If so, I haven't been able find it.

Thanks :)

User avatar
AbaddonOrmuz
Registered User
Posts: 661
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: xsl code help for BBCode please

Post by AbaddonOrmuz » Thu Sep 05, 2019 12:52 pm

You should use {IDENTIFIER} instead of {SIMPLETEXT1}, this last one might generate invalid IDs since it accept some characters not allowed (spaces, commas, dots, minus, plus) for them.

You could use something like:

BBCode:

Code: Select all

[anchor={IDENTIFIER}]{TEXT?}[/anchor]
HTML:

Code: Select all

<span id="{@anchor}"><xsl:apply-templates/></span>
Usage examples:

Code: Select all

[anchor=anchortext]Visible text[/anchor]
[anchor=anchortext][/anchor]
Or if you really need something like [anchor]anchortext[/anchor] then you could swap the tokens:

BBCode:

Code: Select all

[anchor={TEXT?}]{IDENTIFIER}[/anchor]
HTML:

Code: Select all

<span>
	<xsl:attribute name="id">
		<xsl:value-of select="@content"/>
	</xsl:attribute>
	<xsl:if test="@anchor">
		<xsl:value-of select="@anchor"/>
	</xsl:if>
</span>
Usage examples:

Code: Select all

[anchor=Visible text]anchortext[/anchor]
[anchor]anchortext[/anchor]
Some of my phpBB extensions: [ Imgur | SEO Metadata | Markdown ]
Check out all my extensions
Arch Linux user

WainPetopia
Registered User
Posts: 11
Joined: Thu Jul 18, 2019 5:55 am

Re: xsl code help for BBCode please

Post by WainPetopia » Tue Sep 10, 2019 3:32 pm

Thanks for your response! I'm not sure I understood it all, but I'll play with the code till I do (I hope) :)

Does this new form of BBCode introduced in 3.2 have any proper documentation?

Just one example, from reading the comments of you and others I'm guessing that

Code: Select all

<xsl:apply-templates/>
is used to apply the text that the poster provides between the opening and closing BBCode tags. But, how would anyone know that? Is there a document anywhere that states that? :)

User avatar
AbaddonOrmuz
Registered User
Posts: 661
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: xsl code help for BBCode please

Post by AbaddonOrmuz » Tue Sep 10, 2019 5:54 pm

phpBB uses the library s9e/TextFormatter, you can read more about it in the following link:

https://s9etextformatter.readthedocs.io ... de_syntax/
Some of my phpBB extensions: [ Imgur | SEO Metadata | Markdown ]
Check out all my extensions
Arch Linux user

User avatar
Mick
Support Team Member
Support Team Member
Posts: 21462
Joined: Fri Aug 29, 2008 9:49 am
Location: Not watching cricket

Re: xsl code help for BBCode please

Post by Mick » Tue Sep 10, 2019 6:01 pm

WainPetopia wrote:
Tue Sep 10, 2019 3:32 pm
Does this new form of BBCode introduced in 3.2 have any proper documentation?
I’m not certain much has changed as far as phpBB and BBCodes documentation is concerned. It’s the HTML replacements that are changing.
"The more connected we get the more alone we become" - Kyle Broflovski

WainPetopia
Registered User
Posts: 11
Joined: Thu Jul 18, 2019 5:55 am

Re: xsl code help for BBCode please

Post by WainPetopia » Thu Sep 12, 2019 1:18 pm

Mick wrote:
Tue Sep 10, 2019 6:01 pm
WainPetopia wrote:
Tue Sep 10, 2019 3:32 pm
Does this new form of BBCode introduced in 3.2 have any proper documentation?
I’m not certain much has changed as far as phpBB and BBCodes documentation is concerned. It’s the HTML replacements that are changing.
So the use of xsl in BBCodes hasn't been documented? That's what I was asking about :) It seems like the only way for a board owner to figure it out is to look for replies to support issues in a search engine and hope someone has posted something related to your situation.

User avatar
david63
Registered User
Posts: 16417
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: xsl code help for BBCode please

Post by david63 » Thu Sep 12, 2019 2:17 pm

WainPetopia wrote:
Thu Sep 12, 2019 1:18 pm
So the use of xsl in BBCodes hasn't been documented?
Have you read the documention? https://area51.phpbb.com/docs/dev/3.2.x ... codes.html
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Mick
Support Team Member
Support Team Member
Posts: 21462
Joined: Fri Aug 29, 2008 9:49 am
Location: Not watching cricket

Re: xsl code help for BBCode please

Post by Mick » Thu Sep 12, 2019 2:20 pm

Don’t forget XSL isn’t a phpBB thing, all phpBB does is give you the opportunity to use HTML code (or whatever) in posts where it wouldn’t normally be allowed via BBCode. You can get code snippets and information all over the internet.
"The more connected we get the more alone we become" - Kyle Broflovski

User avatar
3Di
Former Team Member
Posts: 14088
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: xsl code help for BBCode please

Post by 3Di » Fri Sep 13, 2019 2:18 am

Mick wrote:
Thu Sep 12, 2019 2:20 pm
Don’t forget XSL isn’t a phpBB thing, all phpBB does is give you the opportunity to use HTML code (or whatever) in posts where it wouldn’t normally be allowed via BBCode.
Why not?

XLS = Style Sheets for XML.

Since 3.2 with the new BBCode engine is able transform XLS into something that is recognized by a browser, like HTML and XHTML.
Normally XSLT does this by transforming each XML element into an (X)HTML element.

https://www.w3schools.com/xml/xsl_intro.asp
https://www.w3schools.com/xml/xsl_languages.asp

https://area51.phpbb.com/docs/dev/3.2.x ... parameters

So yes, phpBB does give you the opportunity to use it.

https://phpbbstudio.com/kb/bbcodes
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1107
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: xsl code help for BBCode please

Post by mrgoldy » Fri Sep 13, 2019 9:09 am

This will give you exactly the use cases you want:

Code: Select all

[anchor={IDENTIFIER;useContent}]{TEXT;optional}[/anchor]

Code: Select all

<span id="{@anchor}">
<xsl:if test="@anchor">
<xsl:apply-templates/>
</xsl:if>
</span>

Post Reply

Return to “Custom BBCode Development and Requests”