Re: [xsl] Newbie Question: Creating Error Description from Invalid Input

Subject: Re: [xsl] Newbie Question: Creating Error Description from Invalid Input
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 13 Oct 2006 15:37:06 +0100
It seems like you mainly want to copy stuff

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

But change request to response

<xsl:template match="request">
<response>
<xsl:apply-templates/>
</response>
</xsl:template>

zap all elements that mach some "error predicate" (no child node in
this case)

<xsl:template match="header/*[not(node()]"/>

If there are any error elements, add an errordescription

<xsl:template match="header">
<header>
<xsl:apply-templates/>
<xsl:variable name="bad" select="*[not(node()]"/>
<xsl:if test="$bad">
 <errorDescription>
  <xsl:text>Invalid Elements:</xsl:text>
  <xsl:for-each select="$bad">
    <xsl:value-of select="name()"/>
    <xsl:if test="position()!=last()">,</xsl:if>
   </xsl:for-each>
 <errorDescription>
</xsl:if>
</header>
</xsl:template>


David

Current Thread