xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Welch" <awe...@piper-group.com>
Subject RE: Have we disobeyed a cardinal rule?
Date Tue, 08 Oct 2002 15:28:12 GMT

This looks fine, your problem must lie elsewhere.

If its not something obvious, try running the xslt through a debugger
such as Xselerator.  Alternatively you could try the 'xx' method - place
some noticable x's in your templates to see if they get copied through
to the output... so in this case I would use x\"x instead of \".  If you
dont see the x's, then that template isnt being fired.

Or, of course, post some source xml, a snippet of your stylesheet and
the required output and someone should be able to help.

cheers
andrew



> -----Original Message-----
> From: Koes, Derrick [mailto:Derrick.Koes@smith-nephew.com]
> Sent: 08 October 2002 14:43
> To: Andrew Welch; Koes, Derrick
> Cc: xalan-j-users@xml.apache.org
> Subject: RE: Have we disobeyed a cardinal rule?
> 
> 
> 
> Here is a snippet of what I've implemented, but does not work 
> as desired.
> I simply get a \ in the input text field, if my original value was ".
> What have I done wrong?
> 
> 
> <xsl:template match="Name">
>     <xsl:variable name="escapedFirstName">
>         <xsl:call-template name="escape">
>             <xsl:with-param name="text" select="FirstName"/>
>         </xsl:call-template>
>     </xsl:variable>
> 
> <table>
>        <tr>
>              <td class='boldSmallFont'><xsl:value-of
> select="$lang.user.name.first"/><xsl:text> * </xsl:text></td>
>               <td><input type="text" name="FirstName"
> value="{$escapedFirstName}" maxlength="25"/></td>
>              </tr>
> 
> 
> 
> <xsl:template name="escape">
>     <xsl:param name="text"/>
>     <xsl:choose>
>       <xsl:when test="contains($text, '&quot;')">
>         <xsl:variable name="bufferBefore" 
> select="substring-before($text,
> '&quot;')" />
>         <xsl:variable name="newBuffer" select="substring-after($text,
> '&quot;')" />
>         <xsl:value-of select="$bufferBefore"/><xsl:text>\"</xsl:text>
>         <xsl:call-template name="escape">
>           <xsl:with-param name="text" select="$newBuffer"/>
>         </xsl:call-template>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:value-of select="$text"/>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
> 
> 
> -----Original Message-----
> From: Andrew Welch [mailto:awelch@piper-group.com] 
> Sent: Tuesday, October 08, 2002 4:28 AM
> To: Koes, Derrick
> Cc: xalan-j-users@xml.apache.org
> Subject: RE: Have we disobeyed a cardinal rule?
> 
> 
> DK:   
> >The escape symbol shows up in the <td>.  
> >It seems it's a usage problem rather than a data problem.
> 
> Ahhh, in that case, you could add a param to your text() template that
> decides whether to call escape-string-for-javascript or not:
> 
> <xsl:template match="text()">
>   <xsl:param name="javascript" select="'no'"/>
>   <xsl:choose>
>     <xsl:when test='contains(.,"&apos;") and $javascript != "no"'>
>       <xsl:call-template name="escape-string-for-javascript">
>         <xsl:with-param name="str" select="." />
>       </xsl:call-template>
>     </xsl:when>
>     <xsl:otherwise>
>       <xsl:value-of select="."/>
>     </xsl:otherwise>
>   </xsl:choose>
> </xsl:template>
> 
> <xsl:template name="escape-string-for-javascript">
>      <xsl:param name="str"/>
>      <xsl:choose>
>        <xsl:when test='contains($str,"&apos;")'>
>          <xsl:variable name="before-first-apostrophe"
>                        select='substring-before($str,"&apos;")'/>
>          <xsl:variable name="after-first-apostrophe"
>                        select='substring-after($str,"&apos;")'/>
>          <xsl:value-of 
> select="$before-first-apostrophe"/>\'<xsl:text/>
>          <xsl:call-template name="escape-string-for-javascript">
>             <xsl:with-param name="str" 
> select="$after-first-apostrophe"
> />
>          </xsl:call-template>
>        </xsl:when>
>        <xsl:otherwise>
>          <xsl:value-of select="$str"/>
>        </xsl:otherwise>
>      </xsl:choose>
>    </xsl:template>
> 
> So when you know that you want to escape ' to \' you can use:
> 
> <xsl:apply-templates>
>   <xsl:with-param name="javascript" select="'yes'"/>
> </xsl:apply-templates>
> 
> or on specific values:
> 
> <xsl:apply-templates select="someValue">
>   <xsl:with-param name="javascript" select="'yes'"/>
> </xsl:apply-templates>
> 
> and when you just want to pass through the text unchanged just use:
> 
> <xsl:apply-templates/>
> 
> (typos in previous post sorted this time ;)
> 
> cheers
> andrew
> 
> 
> -----Original Message-----
> From: Koes, Derrick [mailto:Derrick.Koes@smith-nephew.com]
> Sent: 07 October 2002 19:06
> To: 'Steve Dwire'; xalan-j-users@xml.apache.org
> Cc: Courtney, Brian
> Subject: RE: Have we disobeyed a cardinal rule?
> 
> 
> That would work very well except for when the value needs to 
> be used in
> an input field AND a <td> for example.
> The escape symbol shows up in the <td>.  It seems it's a usage problem
> rather than a data problem.
> 
> -----Original Message-----
> From: Steve Dwire [mailto:sdwire@parkcitysolutions.com] 
> Sent: Monday, October 07, 2002 1:38 PM
> To: xalan-j-users@xml.apache.org
> Subject: RE: Have we disobeyed a cardinal rule?
> 
> I'd suggest building an escape_quotes template to replace all 
> single and
> double quotes with their escaped counterparts (\' and \", 
> respectively).
> This would be a recursive template that outputs everything before the
> quote, then the backslash, then the quote, then everything after the
> quote run recursively through the 'escape_quotes' template again.
> Whenever you need to use an XML value in an attribute (or in a
> javascript, for that matter) call the escape_quotes template with the
> value. This lets the XSL decide what needs to be encoded and what
> doesn't, rather than expecting the XML provider to figure that out for
> you. The downside is the extra overhead of recursive processing in the
> XSL engine.
> 
> -----------------------
> Steve Dwire
> Park City Solutions <http://www.parkcitysolutions.com>
> 500 Park Blvd, Suite 295-C, Itasca, IL  60143
> V: (630) 250-3045, x104
> F: (630) 250-3046
> 
> DISCLAIMER: This message and any included attachments are 
> from Park City
> Solutions Inc. and are intended only for the entity to which it is
> addressed. The contained information is confidential and privileged
> material. If you are not the intended recipient, you are 
> hereby notified
> that any use, dissemination, or copying of this communication is
> strictly prohibited and may be unlawful. If you have received this
> communication in error please notify the sender of the 
> delivery error by
> e-mail or call Park City Solutions Inc. corporate offices at (435)
> 654-0621
> 
> -----Original Message-----
> From: Koes, Derrick [mailto:Derrick.Koes@smith-nephew.com]
> Sent: Monday, October 07, 2002 12:23 PM
> To: 'xalan-j-users@xml.apache.org'
> Subject: Have we disobeyed a cardinal rule?
> 
> 
> We are transforming XML to HTML using XSLT.  The problem is 
> that some of
> the values used to populate the HTML forms have quotes (' " 
> ') in them.
> These values seem to be in a fine state until they are used 
> to populate
> HTML input elements.  We don't URL encode/decode at the 
> moment, but some
> experimentation has shown that if the values are persisted as URL
> encoded then are URL decoded and assigned to the appropriate elements
> AFTER the page loads (e.g. in a onWindowLoad javascript method) things
> are OK.
> 
> We've also seen that this is only a problem when they are 
> being assigned
> to attributes, since attributes use quotes to enclose their values.
> 
> To summarize, it appears we will have to URL encode and URL decode all
> individual values (encoding/decoding as XML does not work 
> well) for our
> app to use these values.  Is this correct?  Is there a better way to
> solve this problem?
> 
> Thanks,
> Derrick
> This electronic transmission is strictly confidential to 
> Smith & Nephew
> and intended solely for the addressee. It may contain 
> information which
> is covered by legal, professional or other privilege. If you 
> are not the
> intended addressee, or someone authorized by the intended addressee to
> receive transmissions on behalf of the addressee, you must not retain,
> disclose in any form, copy or take any action in reliance on this
> transmission. If you have received this transmission in error, please
> notify the sender as soon as possible and destroy this message.
> This electronic transmission is strictly confidential to 
> Smith & Nephew
> and intended solely for the addressee. It may contain 
> information which
> is covered by legal, professional or other privilege. If you 
> are not the
> intended addressee, or someone authorized by the intended addressee to
> receive transmissions on behalf of the addressee, you must not retain,
> disclose in any form, copy or take any action in reliance on this
> transmission. If you have received this transmission in error, please
> notify the sender as soon as possible and destroy this message.
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
>  
> This electronic transmission is strictly confidential to 
> Smith & Nephew and
> intended solely for the addressee.  It may contain 
> information which is
> covered by legal, professional or other privilege.  If you are not the
> intended addressee, or someone authorized by the intended addressee to
> receive transmissions on behalf of the addressee, you must not retain,
> disclose in any form, copy or take any action in reliance on this
> transmission.  If you have received this transmission in error, please
> notify the sender as soon as possible and destroy this message.
> 
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
>  
> 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
 

Mime
View raw message