Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

how to extract nodes not containing certain text

i have xml like attached. using xslt 1.0  I need create a record for each project Id entry, except those with <phase> value="new"
<?xml version="1.0" encoding="UTF-8"?>
<projects>
	<project id="195">
		<title>The use of virtual worlds for effective education</title>
		<url>http://www.campbellcollaboration.org/lib/project/195/</url>
		<published_authors>Stewart Martin</published_authors>
		<publishing_date>2011-10-18</publishing_date>
		<keywords/>
		<groups>Education</groups>
		<phase>title_proposal</phase>
		<files>
			<file id="1513">
				<title>Martin_Virtual_Worlds_Title.pdf</title>
				<url>http://www.campbellcollaboration.org/lib/download/1513/</url>
				<filename>Martin_Virtual_Worlds_Title.pdf</filename>
				<filesize>78729</filesize>
				<project_phase>title_proposal_publishing</project_phase>
				<type>title_proposal</type>
				<mime_type>application/pdf</mime_type>
				</file>
		</files>
	</project>
	
	<project id="171">
		<title>The effect of benefit exhaustion on employment</title>
		<url>http://www.campbellcollaboration.org/lib/project/171/</url>
		<published_authors>Trine Filges, Lars Pico Geerdsen, Anne-Marie Jørgensen, Krystyna Kowalski, Anne-Sofie  Due Knudsen</published_authors>
		<publishing_date>2011-10-14</publishing_date>
		<keywords>Unemployment benefit; Employment status; </keywords>
		<groups>Social Welfare</groups>
		<phase>new</phase>
		<files>
			<file id="1507">
				<title>Filges_Benefit_Exhaustion_Protocol.pdf</title>
				<url>http://www.campbellcollaboration.org/lib/download/1507/</url>
				<filename>Filges_Benefit_Exhaustion_Protocol.pdf</filename>
				<filesize>248238</filesize>
				<project_phase>protocol_publishing</project_phase>
				<type>protocol</type>
				<mime_type>application/pdf</mime_type>
				</file>
		</files>
	</project>
	
	<project id="179">
		<title>The effect of benefit exhaustion on employment</title>
		<url>http://www.campbellcollaboration.org/lib/project/171/</url>
		<published_authors>Trine Filges, Lars Pico Geerdsen, Anne-Marie Jørgensen, Krystyna Kowalski, Anne-Sofie  Due Knudsen</published_authors>
		<publishing_date>2011-10-14</publishing_date>
		<keywords>Unemployment benefit; Employment status; </keywords>
		<groups>Social Welfare</groups>
		<phase>protocol</phase>
		<files>
			<file id="1507">
				<title>Filges_Benefit_Exhaustion_Protocol.pdf</title>
				<url>http://www.campbellcollaboration.org/lib/download/1507/</url>
				<filename>Filges_Benefit_Exhaustion_Protocol.pdf</filename>
				<filesize>248238</filesize>
				<project_phase>protocol_publishing</project_phase>
				<type>protocol</type>
				<mime_type>application/pdf</mime_type>
				</file>
		</files>
	</project>
	</projects

Open in new window

0
mmalik15
Asked:
mmalik15
  • 3
1 Solution
 
sshah254Commented:
<xsl:for-each select="./Project">
    <xsl:if test="./phase!='new'">
        ... do your processing here
    <xsl:if>
</xsl:for>

SS
0
 
Geert BormansCommented:
The above suggested XSLT assumes you start from the context of Projects and has some smaller flaws

You should never put the ./ for a direct child, be selective inside a predicate instead of a xsl:if, XML is case sensitive and avoid != since you could meet a set comparisson


<xsl:for-each selec="/projects/project[not(normalize-space(phase) = 'new')]">
   <!-- do your stuff here -->
</xsl:for-each>
0
 
Geert BormansCommented:
I had a typo (missing t)

tested example
<xsl:template match="/">
        <xsl:for-each select="/projects/project[not(normalize-space(phase) = 'new')]">
            <!-- do your stuff here -->
            <record><xsl:value-of select="@id"/></record>
        </xsl:for-each>        
    </xsl:template>

Open in new window

0
 
mmalik15Author Commented:
Thanks
0
 
Geert BormansCommented:
welcome
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now