Horouncohof
New Member
I'm trying to write an HTML to BBCode converter, but being a complete newb in XSL I need help breaking the ice. Here's what I've got so far:\[code\]<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" encoding="UTF-8"><xslutput method="text" omit-xml-declaration="yes" indent="no" encoding="UTF-8"/><xsl:template match="h1|h2|h3|h4">[h]<xsl:apply-templates/>[/h]</xsl:template><xsl:template match="b|strong"><xsl:apply-templates/></xsl:template><xsl:template match="i|em"><xsl:apply-templates/></xsl:template><xsl:template match="u"><xsl:apply-templates/></xsl:template><xsl:template match="br">
</xsl:template><xsl:template match="p">
<xsl:apply-templates/>
</xsl:template><xsl:template match="img">
</xsl:template><xsl:template match="a"><xsl:apply-templates/></xsl:template><xsl:template match="style|script"></xsl:template></xsl:stylesheet>\[/code\]How would you match \[code\]<a>\[/code\] that have a specific keyword in \[code\]href\[/code\] and remove those nodes, while keeping others? And then check if those \[code\]<a>\[/code\] are empty or not, thus deciding whether to use \[code\]http://foo\[/code\] or \[code\]bar\[/code\]?For example:\[code\]<a href="http://spammycrap.tld">Foo</a><a href="http://empty.tld"></a><a href="http://okay.tld">Baz</a>\[/code\]Desired output:\[code\]http://empty.tldBaz\[/code\]
</xsl:template><xsl:template match="p">
<xsl:apply-templates/>
</xsl:template><xsl:template match="img">