Solved

How to remove values and parentheses from a string?

Posted on 2007-04-05
4
226 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now