XSL: Several XML files into one file

We have a lot of separate files and want to put them together into one.

Step 1: Create a list of all filenames as XML file

<files>
<file>file1.xml</file>
<file>file2.xml</file>
<file>file3.xml</file>
</files>

Step 2: Create an XSL transform

<xsl:template match="//files">
<Root>
<xsl:for-each select="file">
<xsl:copy-of select="document(.)"/>
</xsl:for-each>
</Root>
</xsl:template>

Note the use of “copy-of” – it will copy all the nodes and attributes from the source XML.

VbScript: Number of days in month

Code:

daysInMonth = Day(DateSerial(thisYear, thisMonth + 1, 0))

It adds 1 to the month and uses DateSerial to get a Date representing the 0th day of the following month. That is the last day of the month you entered. The Day function gives you the number of that day, which equals the number of days in the month.

How to split a string with XSL

I needed to break a string like this “Hot Waffles,Fresh Fruits,Pastries,Bagels,Cereals,Muffins,Juices,Milk,Coffee” into separate XML elements. How to do it? Use a “tokenize” function!

<xsl:template name=”breakfast”>
<xsl:param name=”allItems”/>
<xsl:for-each select=”tokenize($allItems, ‘,’)”>
<item><xsl:value-of select=’.’/></item>
</xsl:for-each>
</xsl:template>

Result:

<item>Hot Waffles</item>
<item>Fresh Fruits</item>
<item>Pastries</item>
<item>Bagels</item>
<item>Cereals</item>
<item>Muffins</item>
<item>Juices</item>
<item>Milk</item>
<item>Coffee</item>