Is there a way to open a tag and not close it? For example:
<xsl:for-each select=".">
<span>
</xsl:for-each>
This is my code: http://pastebin.com/1Xh49YN0 . As you can see i need to open on a when tag and close it on another when tag (row 43 and 63).
This piece of code is not valid because XSLT is not well formed, but is there a way to do a similar thing? Thank you
You can't - XSLT isn't about generating a text file or a sequence of characters, it's about transforming one document tree into another. That the tree eventually gets serialized into a textual format is incidental.
This is why, for example, you can't choose between and in the output file - they're both represent exactly the same document tree.
You can almost always achieve what is intended by refactoring into separate templates that call each other.
You can use disable-output-escaping, but it's generally considered a bit of a hack, and I understand it's deprecated in XSLT 2.
Untested, obviously, but if I understood your original code correctly, this should be pretty close.
Hint:
<xsl:when test="(. - $current_pos) eq 0">
is equivalent to<xsl:when test=".=$current_pos">
. ;-)Move the content between the two existing
xsl:choose
elements to a new templateIn the
xsl:when
, open and close yourspan
. Inside thespan
, call this new template.Add an
xsl:otherwise
to thexsl:choose
, in this, call the template, without adding aspan
.As a general point, try to use
xsl:apply-templates
a bit more often, rather thanxsl:for-each
, it should make it easier to understand what is going on.