Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to remove values and parentheses from a string?

Posted on 2007-04-05
4
Medium Priority
?
234 Views
Last Modified: 2012-06-22
Greetings,

How can I only return the string value that is not included within parentheses?  For example, if I have an element <LINK TTL="17" S="210.4-01(a)(3)(i)(A)"> and I would only like the @S attribute to only return "210.4-01", how can this be processed?

Any advice or guidance is greatly appreciated!

Best regards,
Jamie
0
Comment
Question by:jmc430
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:BobSiemens
ID: 18862350
<xsl:template name="DumpNonParenData">
  <xsl:param name="TheString" />
  <xsl:choose>
    <xsl:when test="contains($TheString, '(')">



0
 
LVL 10

Accepted Solution

by:
BobSiemens earned 1600 total points
ID: 18862370
Oops

This is a quick, typed from the top of my head, method.  

Basically, you recursively call the function.  It will dump the whole string if there are no parens.  If there are parens, it dumpt the pre-paren part and calls itself with the post-paren part.

<xsl:template name="DumpNonParenData">
  <xsl:param name="TheString" />
  <xsl:choose>
    <xsl:when test="contains($TheString, '(')">
      <xsl:value-of select="substring-before($TheString, '(')"/>
      <xsl:call-template name="DumpNonParenData">
        <xsl:with-param name="TheString" >
          <xsl:value-of select="substring-after($TheString, ')')"/>
        </xsl:with-param>
      </xsl:call-template>      
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$TheString"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
 
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 400 total points
ID: 18862656
If you are using XSLT1 you need a recursive method as Bob suggested

This example is a perfect usecase for XSLT2 though.
(If I had to do some similar things like this in a project, I would use XSLT2)
So if by any chance you can use Saxon8B in this project,
I recommend you do
Here is the XSLT2 solution, look how easy with regular expressions

    <xsl:template match="LINK">
        <xsl:value-of select="replace(@S, '\([^\)]+\)', '')" />
    </xsl:template>

cheers

Geert
0
 

Author Comment

by:jmc430
ID: 18864805
Hi Geert,

Thanks for your helpful response!
I cannot use Saxon8B, but I appreciate your comments!

Hi BobSiemens,

Thanks for your solution.  It works!

Thanks again and happy holidays! :)
0

Featured Post

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question