XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Victoria LuSubject: How do I strip out a comma ast last and a following zip value?
Author: Victoria Lu
Date: 08 May 2008 04:12 PM
If preceding-sibling type="zMADDRESS", type="zZip" value should be left unchanged. Else if, preceding-sibling type="zADDRESS", type="zZip" items should be removed.

And the comma and space which always seem to precede the zZip in ZAddress or zNeighb must also be removed--if that is all within a zADDRESS.

Foe examples:
1. Before:
<tps:c type="zStreet">20 West Row</tps:c>
<tps:c type="zAddress">,</tps:c>
<tps:c type="zNeighb">Canberra City,</tps:c>
<tps:c type="zZip">2600</tps:c>

1. After:
<tps:c type="zStreet">20 West Row</tps:c>
<tps:c type="zAddress">,</tps:c>
<tps:c type="zNeighb">Canberra City</tps:c>

2. Before:
<tps:c type="zStreet">82 Northbourne Ave.</tps:c>
<tps:c type="zAddress">,</tps:c>
<tps:c type="zNeighb">Braddon</tps:c>
<tps:c type="zAddress">,</tps:c>
<tps:c type="zZip">2601</tps:c>

2. After:
<tps:c type="zStreet">82 Northbourne Ave.</tps:c>
<tps:c type="zAddress">,</tps:c>
<tps:c type="zNeighb">Braddon</tps:c>

3. Beofre:
<tps:c type="zMaddress">Box 544, Burra Creek,</tps:c>
<tps:c type="zCity">Queanbeyan,</tps:c>
<tps:c type="zZip">2620</tps:c>

3. After, no change because one its preceding-siblings is "zMaddress".

I attached a whole file here.

Please help me.

Thanks a lot,
Victoria


Unknowncontent.cxml_original_zZIP.cxml

Postnext
Elias HuterSubject: How do I strip out a comma ast last and a following zip value?
Author: Elias Huter
Date: 09 May 2008 04:00 AM
The example link seems to be broken.

Postnext
Tony LavinioSubject: How do I strip out a comma ast last and a following zip value?
Author: Tony Lavinio
Date: 09 May 2008 08:57 AM
Our malicious-file filter seems to have quarantined the file,
probably because it doesn't recognize '.cxml'.

Could you zip the file and reattach it?

Postnext
Victoria LuSubject: How do I strip out a comma ast last and a following zip value?
Author: Victoria Lu
Date: 09 May 2008 10:45 AM
here I converted the file with .xml


Unknowncontent.cxml_original_zZIP.zip

Postnext
Minollo I.Subject: How do I strip out a comma ast last and a following zip value?
Author: Minollo I.
Date: 09 May 2008 02:05 PM
Something like this may be a good starting point:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tps="http://www.typefi.com/ContentXML">

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

<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="*|text()"/>
</xsl:element>
</xsl:template>

<xsl:template match="tps:c[@type='zZip']">
<xsl:choose>
<xsl:when test="preceding-sibling::tps:c[@type='zAddress']">
<!-- removed -->
</xsl:when>
<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="tps:c[@type='zAddress']">
<xsl:choose>
<xsl:when test="text() = ',' and following-sibling::tps:c[1][@type='zZip']">
<!-- removed -->
</xsl:when>
<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

Postnext
Victoria LuSubject: How do I strip out a comma ast last and a following zip value?
Author: Victoria Lu
Date: 09 May 2008 03:37 PM
That's great!

How do I remove only the last comma ',' in zAddress if there are more than one ','s in zAddress?

Thank you so much for the big help.

Postnext
Minollo I.Subject: How do I strip out a comma ast last and a following zip value?
Author: Minollo I.
Date: 09 May 2008 03:58 PM
I'm not sure I understand what logic you need to use there; but you can surely play with substring() and/or contains() to tweak the condition and the result; for example, if you want to remoe the last trailing ",", you could do...

<xsl:template match="tps:c[@type='zAddress']">
<xsl:choose>
<xsl:when test="substring(text(), string-length(text()), 1) = ',' and following-sibling::tps:c[1][@type='zZip']">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
<xsl:value-of select="substring(text(), 1, string-length(text()) - 1)"/>
</xsl:element>
</xsl:when>
<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>

Posttop
Victoria LuSubject: How do I strip out a comma ast last and a following zip value?
Author: Victoria Lu
Date: 09 May 2008 04:09 PM
Yes, that's what I want.

Many, many thanks to you.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.