Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where am i going wrong in my xsl transformation

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following .xml with the following struncture <records>
<record>
<author>
<event_time>
....
</record>
...
I then whish to transfer it to text to be included
within an email. Im trying to align all the columns so that the document is easier to read. So
Im attepting to read the element and check if its
of length 20 and if not keep looping adding whitespaces until you reach 20. My problem now is that nothing happens. Where am I going wrong in my xsl document. Thank you for your time

<xsl utput method="text" indent="yes"/>

<xsl:template match="/">

<xsl:apply-templates select="records"/>
</xsl:template>

<xsl:template name="author" match="author">
<xsl aram name="aut"><xsl:value-of select="."/></xsl aram>
<xsl:choose>
<xsl:when test="string-length('$aut') < 20"><xsl:call-template name="author">
<xsl:with-param name="aut" select="concat('$aut', ' ')"/>
</xsl:call-template></xsl:when>
<xsl:when test="string-length('$aut') = 20"><xsl:value-of select="$aut"/><xsl:text> </xsl:text></xsl:when>
</xsl:choose>
</xsl:template>
 
Dhananjay Goswami
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line causing the problem is the
<xsl:apply-templates select="records"/>.
and you don't have the template for 'records' defined anywhere.
Try changing this to:
<xsl:apply-templates select="author"/>
or create a template for 'records' and call the 'author' template eith the corresponding parameter.
All the best.
Dhananjay.
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the following and i still get no output
Any ideas?
<xsl:template match="/">
<xsl:for-each select="records/record">
<xsl:apply-templates select="author"/>
</xsl:for-each>
</xsl:template>

<!--<xsl:template match="record">-->
<!--<xsl:number/>.-->
<xsl:template name="author" match="author">
<xsl aram name="aut"><xsl:value-of select="."/></xsl aram>
<xsl:choose>
<xsl:when test="string-length('$aut') < 20"><xsl:call-template name="author">
<xsl:with-param name="aut" select="concat('$aut', ' ')"/>
</xsl:call-template></xsl:when>
<xsl:when test="string-length('$aut') = 20"><xsl:value-of select="$aut"/><xsl:text> </xsl:text></xsl:when>
</xsl:choose>
</xsl:template>
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be easier to define a variable of 20 blanks
<xsl:variable name="twentyBlanks">                    *</xsl:variable>
(doesn't work without "*" at the end)
and then cut as many blanks as you need to lengthen your aut variable:
<xsl:variable name="test" select="concat(
$aut,
substring($twentyBlanks, 1, 20 - string-length($aut))
)"/>*

[ March 10, 2003: Message edited by: Mapraputa Is ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic