<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Public Mindcss</title>
	<atom:link href="http://publicmind.in/blog/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://publicmind.in/blog</link>
	<description>Simple and Sophisticated</description>
	<lastBuildDate>Fri, 27 May 2011 08:28:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP: Select HTML elements with more than one css class using XPath</title>
		<link>http://publicmind.in/blog/html-elements-with-more-than-one-css-class/</link>
		<comments>http://publicmind.in/blog/html-elements-with-more-than-one-css-class/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 22:39:43 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://publicmind.in/blog/?p=309</guid>
		<description><![CDATA[Recently, while working on my project FeedAPI ImageGrabber I came across the issue where I had to select HTML elements by a given css class. The HTML element can have a single CSS class: &#60;div class=&#34;foo&#34;&#62;&#60;/div&#62; or multiple CSS classes associated with it. &#60;div class=&#34;foo exp tar&#34;&#62;&#60;/div&#62; Now if you want to select the HTML [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, while working on my project <a href="http://publicmind.in/blog/feedapi-imagegrabber">FeedAPI ImageGrabber</a> I came across the issue where I had to select HTML elements by a given css class. The HTML element can have a single CSS class:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span></div></div>
<p>or multiple CSS classes associated with it.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;foo exp tar&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span></div></div>
<p>Now if you want to select the HTML elements with class &#8220;foo&#8221;, this div element would be one of them.<br />
<span id="more-309"></span><br />
As, I do not have much experience with XPath, I started to search for a solution. After a lot of search and discussion on Drupal development mailing lists, I arrived at the following XPath :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #666666; font-style: italic;">//*[@class and contains(concat(' ',normalize-space(@class),' '),' $classname ')]</span></div></div>
<p>The <strong>normalize-space</strong> function replaces all continuous tabs and whitespaces with a single whitespace character. Then, we concatenate the resulting string with two white-spaces, one in the start and other at the last. At last, we search for</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$classname</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span></div></div>
<p>in the final string.</p>
<p>I hope it helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/html-elements-with-more-than-one-css-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

