This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: SubString Issue!
- To: xsl-list at mulberrytech dot com
- Subject: RE: SubString Issue!
- From: "Mabry, F. DR EECS" <df6954 at exmail dot usma dot army dot mil>
- Date: Thu, 22 Jun 2000 14:26:02 -0400
- Reply-To: xsl-list at mulberrytech dot com
For the following XML (note I made a change to the source)
<test>
<CreditCard><Highlight>9999-9999-9999-9999</Highlight></CreditCard>
<Name>Jennifer <Highlight>Anniston</Highlight></Name>
<Date.of.Birth>10-06-1969</Date.of.Birth>
</test>
use the following transform:
<?xml version="1.0"?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:saxon="http://icl.com/saxon"
extension-element-prefixes="saxon">
<xsl:template match="CreditCard">
<xsl:variable name="mask"><xsl:text>XXXX</xsl:text></xsl:variable>
<Text>
<xsl:value-of select="substring(//CreditCard/Highlight/text(), 1, 15)"/>
<xsl:value-of select="$mask"/>
</Text>
</xsl:template>
</xsl:transform>
This will get the desired result (I believe). Note: template has a "match"
attribute instead of name attribute. The expression how references a
"findable" result in the XML source node set.
Frank
Dr. Frank Mabry
Dept. of EE&CS, U.S. Military Academy
West Point, NY 10996
email: df6954@exmail.usma.edu
Phone: (845) 938-2960
-----Original Message-----
From: Chowdhury, Anisuzzaman
[mailto:Anisuzzaman.Chowdhury@westgroup.com]
Sent: Thursday, June 22, 2000 12:17 PM
To: 'XSL-List@mulberrytech.com'
Subject: SubString Issue!
Part of the XML data:
<CreditCard><Highlight>9999-9999-9999-9999</Highlight></CreditCard>
<Name>Jennifer <Highlight>Anniston</Highlight></Name>
<Date.of.Birth>10-06-1969</Date.of.Birth>
I would like to replace all the "Highlight" tags with "B"
and mask the last
four digits of the credit card number.
Here are the templates I've created:
To replace "Highlight" with "B":
<xsl:template match="Highlight">
<B><xsl:apply-templates/></B>
</xsl:template>
To apply mask:
<xsl:template name="CreditCard">
<xsl:variable
name="mask"><xsl:text>XXXX</xsl:text></xsl:variable>
<Text>
<xsl:value-of select="substring(CreditCard/text(), 1,
15)"/><xsl:value-of
select="$mask"/>
</Text>
</xsl:template>
Whenever I try to run this stylesheet on eXcelon Stylus XSLT
processor, I
get an error message saying "Out of bounds arguments to
substring function".
Using SAX parser, I get the following output:
<Text>XXXX</Text>
The problem is, "Highlight" tag can be anywhere. Is there
any way I can get
the following output:
<Text><B>9999-9999-9999-XXXX</B></Text>
........................................................................
I would highly appreciate your suggestions.
Thanks,
Anis Chowdhury
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list