
I’ve started using XSLT to transform XML in the Pagelet Wizard recently and wanted to share some tips from what I have learned.
1) XMLper - Transform - This is a handy, easy to use, free, online XSL transformer. Input the XML you want to transform and the XSL to do it, and it gives you the output, or associated errors. The specific error messages are really handy, especially if you are doing XSL for Pagelets in PeopleSoft as you just get an error saying it’s failed.
2) Generating HTML using XSL is tricky, unless you have a very straightforward and simple structure (in which case you probably don’t even need a stylesheet). The engine tries to close any open tags in a ‘greedy’ way. For example, the following caused me great angst:
<div>
<xsl:if test=”position() mod 4 = 0”>
</div>
<div>
</xsl:if>
</div>
What I was trying to do here was create a new div in certain circumstances. However, XSL still needs to be valid XML and the above snippet of couse is not. In order to get around this, you can write the HTML as text values and then when its processed by the XSL engine it is read as text but when rendered by the browser it’s treated as HTML. This can be done as follows:
<div>
<xsl:if test=”position() mod 4 = 0”>
<xsl:text disable-output-escaping=”yes”></div></xsl:text>
<xsl:text disable-output-escaping=”yes”><div></xsl:text>
</xsl:if>
</div>
3) Getting JavaScript to run is also a pain, and can be achieved in the same manner as above:
<script type=”text/javascript”>
</xsl:text>
</script>
Several recommendations online suggested using <xsl:comment>, but I found that this left the code completely commented out, and therefore didn’t run - I wonder if this may be a specific PeopleSoft problem though.
4) You can put logic into a for loop to only run the code in the loop in those conditions:
<xsl:for-each select=”/NavCollection/Contents/NavItem[position() <= (ceiling(last() div 4))]”>
— Only run what is inside this loop so long as the current position number meets the criteria
</xsl:for-each>














