Solved

How to remove values and parentheses from a string?

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mongodb hierarchy 2 55
API Soap Calls 4 113
MS Access how to nest many values to one value when exporting query to XML format 8 54
XML response optional elements 12 40
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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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