[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Newbie Question: Creating Error Description from

Subject: Re: Newbie Question: Creating Error Description from Invalid Input
From: Richard Lewis <richardlewis@xxxxxxxxxxxxxx>
Date: Fri, 13 Oct 2006 15:41:04 +0100
Re:  Newbie Question: Creating Error Description from
On Friday 13 October 2006 15:20, Badari wrote:
> I am a newbie to XSL and am hoping that somebody can help me with the
> following scenario. I tried to use xsl:variable but was not successful. :(
>
> I have an "errorDescription" element in the target structure. Depending on
> the error condition result on input fields, I have to concatenate the field
> names (that are in error) and post them to the errorDescription field.
>
> How can I do it?  Any help is appreciated.
>
> sample input.
>
> <request>
>  <header>
>   <address1>1234</address1>
>   <address2></address2>
>   <address3>3456</address3>
>   <address4></address4>
>  </header>
> </request>
>
> If all address elements are expected to have values, and 2nd and 4th don't
> have values the output file should look like:
>
> <response>
>  <header>
>   <address1>1234</address1>
>   <address3>3456</address3>
>   <errorDescription>Invalid Elements: Address2,Address4</errorDescription
>  </header>
> </response>
>

<xsl:template match="header">
  <header>
    <xsl:apply-templates mode="valid" />
  </header>
  <errorDescription>
    <xsl:apply-templates mode="invalid" />
  </errorDescription>
</xsl:template>

<xsl:template match="*" mode="valid">
  <xsl:if test="string(.)!=''">
    <xsl:element name="name()">
      <xsl:apply-templates />
    </xsl:element>
  </xsl:if>
</xsl:template>

<xsl:template match="*" mode="invalid">
  <xsl:if test="string(.)=''">
    <xsl:value-of select="name()" />
    <xsl:if test="position()!=last()">; </xsl:if>
  </xsl:if>
</xsl:template>

I haven't tested it.

If there is a XPath expression to match elements by whether they have any text 
content or not which would be better:

<xsl:template match="header">
  <header>
    <xsl:apply-templates select="all address* children with content" />
  </header>
  <xsl:if test="count(all address* children without content) &gt; 0">
    <errorDescription>
      <xsl:value-of select="all address* children without content" />
    </errorDescription>
  </xsl:if>
</xsl:template>

Any ideas if such an XPath exists?

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
Sonic Arts Research Archive
http://www.sara.uea.ac.uk/
JID: ironchicken@xxxxxxxxxxxxxxx
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.