?
Solved

how to seperate each entry of a node with a full stop (if one is not already present) using xslt 1.0 or xpath 1.0

Posted on 2011-09-19
4
Medium Priority
?
389 Views
Last Modified: 2013-11-18
hi experts,

My xml is attached. My requirement is to separate each entry of <abst> with full stop (if one not already present) and a space. I have tried something like this in xslt but it does not seem to work

<xsl:stylesheet version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 
  <xsl:template match="/">
    <records>
      <xsl:for-each select="/ListRecords/record">
        <record>
         
          <body>
          <xsl:for-each select="metadata/ovidrec/abst" >
            <xsl:value-of select='concat(.," ")'   />
            </xsl:for-each>
          </body>
         
          </record>
         
          </xsl:for-each>
          </records>
         
          </xsl:template>
</xsl:stylesheet>


 
<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
	<responseDate>2011-08-12 05:55:03</responseDate>
	<request verb="ListRecords">http://an.oa.org/OAI-script</request>
	<ListRecords>
		<record>
			<header>
				<identifier>ovid:/bib/cochdb/CD000008</identifier>
				<datestamp>2011-08-12</datestamp>
				<setSpec>BibDB:coch</setSpec>
			</header>
			<metadata>
				<ovidrec xmlns="http://ovid.com/rec/elements/1.0/" xsi:schemaLocation="http://ovid.com/rec/elements/1.0/">
					<acno>CD000008</acno>
					<auts>McCarney, Robert W</auts>
					<auts>Brinkhaus, Benno</auts>
					<auts>Lasserson, Toby J</auts>
					<auts>Linde, Klaus</auts>
					<year>2009</year>
					<doct>Reviews</doct>
					<titl>Acupuncture for chronic asthma</titl>
					<suba>Chronic asthma - non-pharmacological interventions</suba>
					<suba>Acupuncture, homoeopathy and herbal remedies</suba>
					<suba>Humans</suba>
					<suba>*Acupuncture Therapy</suba>
					<suba>*Asthma/th [therapy]</suba>
					<suba>Chronic Disease</suba>
					<suba>Randomized Controlled Trials as Topic</suba>
					<jour>Cochrane Database of Systematic Reviews</jour>
					<lang>English</lang>
					<issu>3</issu>
					<upcd>20093</upcd>
					<grpn>Cochrane Airways Group</grpn>
					<pubt>Systematic Review</pubt>
					<ftlk>CD000008</ftlk>
					<abst>Background</abst>
					<abst>Acupuncture has traditionally been used to treat asthma in China and is used increasingly for this purpose internationally.</abst>
					<abst>Objectives</abst>
					<abst>The objective of this review was to assess the effects of acupuncture for the treatment of asthma or asthma-like symptoms.</abst>
					<abst>Search strategy</abst>
					<abst>We searched the Cochrane Airways Group Specialised Register (last searched August 2008), the Cochrane Complementary Medicine Field trials register, AMED, and reference lists of articles. We also contacted trialists and researchers in the field of complementary and alternative medical research.</abst>
					<abst>Selection criteria</abst>
					<abst>Randomised and possibly randomised trials using needle acupuncture or other forms of stimulation of acupuncture. Any form of control treatment was considered (no treatment in addition to conventional asthma treatment, sham or placebo interventions, active comparator interventions). Studies were included provided outcome was assessed at one week or more.</abst>
					<abst>Data collection and analysis</abst>
					<abst>At least two reviewers independently assessed trial quality. A reviewer experienced in acupuncture assessed the adequacy of the active and sham acupuncture used in the studies. Study authors were contacted for missing information.</abst>
					<abst>Main results</abst>
					<abst>Twelve studies met the inclusion criteria recruiting 350 participants. Trial reporting was poor and trial quality was deemed inadequate to generalise findings. There was variation in the type of active and sham acupuncture, the outcomes measured and time-points presented. The points used in the sham arm of some studies are used for the treatment of asthma according to traditional Chinese medicine. Two studies used individualised treatment strategies and one study used a combination strategy of formula acupuncture with the addition of individualised points. No statistically significant or clinically relevant effects were found for acupuncture compared to sham acupuncture. Data from two small studies were pooled for lung function (post-treatment FEV1): Standardised Mean Difference 0.12, 95% confidence interval -0.31 to 0.55).</abst>
					<abst>Authors' conclusions</abst>
					<abst>There is not enough evidence to make recommendations about the value of acupuncture in asthma treatment. Further research needs to consider the complexities and different types of acupuncture.</abst>
				</ovidrec>
			</metadata>
		</record>
		</ListRecords>
</OAI-PMH>

Open in new window

0
Comment
Question by:mmalik15
[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
  • 3
4 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36559653

<xsl:stylesheet version="1.0"   
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:oai="http://www.openarchives.org/OAI/2.0/"
    xmlns:ovid="http://ovid.com/rec/elements/1.0/"
    exclude-result-prefixes="oai ovid">
    
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    
    <xsl:template match="/">
        <records>
            <xsl:apply-templates select="//oai:ListRecords/oai:record"/>
        </records>
        
    </xsl:template>
    
    <xsl:template match="oai:record">
        <record>
            <body>
                <xsl:apply-templates select="oai:metadata/ovid:ovidrec/ovid:abst" />
            </body>
        </record>
    </xsl:template>
    
    <xsl:template match="ovid:abst">
        <xsl:if test="not(position() = 1)">
            <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="substring(., 1, string-length(.) - 1)"/>
        <xsl:value-of select="translate(substring(., string-length(.)), '.', '')"/>
        <xsl:text>.</xsl:text>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 36559663
well, there are a number of namespaces in your source document (as a default namespace)
In your XSLT you need to address them with a prefix
I think that is the main error in your attempt

It is nicer to have apply-templates instead of for-each, so I did that too

The ". " at the end is done like this

- put all but the last character
- put the last character if it is not a dot (done by removing the dot with a translate)
- put a dot, always
- put a space before the string, except at the beginning
0
 

Author Closing Comment

by:mmalik15
ID: 36560022
perfect!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36560118
welcome
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 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