I'm using an XSLT sheet to transform an XML file to a fixed with text file.
My "solution" to make the fixed width fields is to pad them out with leading zeros, I've attempting to do this with the following template
<xsl:template name="padout" >
<xsl:param name="str"/>
<xsl:param name="chr"/>
<xsl:param name="len"/>
<xsl:variable name="pad">
<xsl:for-each select="1 to $len">
<xsl:value-of select="$chr" />
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring(concat($str,$pad),1,$len)"/>
And calling it as so:
<xsl:call-template name="padout">
<xsl:with-param name="str" select="ancestor::PMI/Home/Name"/>
<xsl:with-param name="chr" xml:space="default"/>
<xsl:with-param name="len" select="30"/>
</xsl:call-template>
But I get an error saying
Expected end of the expression, found 'to '.
I'm assuming it's referring to the "to" in the for-each line.
I'm using this in a .NET 4.5.2 application in VS2015
var transform = new XslCompiledTransform();
transform.Load(path);
using (StringWriter writer = new StringWriter())
{
transform.Transform(pmi, null, writer);
}
I'm not experienced with XSLT and I'm now getting frustrated as I've being wrestling with this all afternoon and Google isn't my friend on this one!
EDIT: If VS2015 can't handle XSLT 2.0 can anyone suggest a way to do this in 1.0?