Solved

How to remove values and parentheses from a string?

Posted on 2007-04-05
4
230 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 400 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 100 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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