Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

xml - Xpath deepest node whose string content is longer than a given length -


how 1 use xpath find deepest node matches string content length constraint.

given chunk of xhtml (or xml) looks this:

<html>     <body>         <div id="page">              <div id="desc">                   wool sweater has following features:                   <ul>                        <li>4 buttons</li>                        <li>merino wool</li>                   </ul>              </div>         </div>         ...      </body> </html> 

an xpath expression like

//*[string-length() > 50] 

would match <html>, <body>, <div id="page"> , <div id="desc">. how can 1 make xpath pick deepest matching node (ie: <div id="desc">)?

bonus points, how 1 apply constraint space normalized content length?

this cannot expressed single xpath 1.0 expression (not using variables)

a single xpath 2.0 expression:

//*[string-length(.) > 50]       [count(ancestor::*) >= //*[string-length(.) > 50]/count(ancestor::*)] 

an xpath 1.0 expression using variable:

//*[string-length() > 50]          [not(//*[string-length() > 50          , count(ancestor::*) > $vnumancestrors])          ] 

where variable vnumancestrors holds value of count(ancestor::*) context node.

the latter expression can implemented in hosting language, such xslt 1.0 or dom.

here 1 xslt 1.0 implementation:

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output omit-xml-declaration="yes" indent="yes"/>   <xsl:template match="/*">   <xsl:variable name="vlongtextelements"    select="//*[string-length()>50]"/>    <xsl:for-each select="$vlongtextelements">    <xsl:variable name="vnumancestrors"         select="count(ancestor::*)"/>      <xsl:copy-of select=     "(.)[not(//*[string-length() > 50             , count(ancestor::*) > $vnumancestrors])          ]     "/>   </xsl:for-each>  </xsl:template> </xsl:stylesheet> 

when transformation applied on provided xml document:

<html>     <body>         <div id="page">             <div id="desc">                                wool sweater has following features:                                                 <ul>                     <li>4 buttons</li>                     <li>merino wool</li>                 </ul>             </div>         </div>                      ...                        </body> </html> 

the wanted, correct result produced:

<div id="desc">                                wool sweater has following features:                                                 <ul>        <li>4 buttons</li>        <li>merino wool</li>     </ul>  </div> 

bonus points, how 1 apply constraint space normalized content length?

very simple implement atop of last solution:

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output omit-xml-declaration="yes" indent="yes"/>   <xsl:template match="/*">   <xsl:variable name="vlongtextelements"    select="//*[string-length(normalize-space())>50]"/>    <xsl:for-each select="$vlongtextelements">    <xsl:variable name="vnumancestrors"         select="count(ancestor::*)"/>      <xsl:copy-of select=     "(.)[not(//*[string-length(normalize-space()) > 50             , count(ancestor::*) > $vnumancestrors])          ]     "/>   </xsl:for-each>  </xsl:template> </xsl:stylesheet> 

and initial xpath 2.0 expression modified one:

//*[string-length(normalize-space(.)) > 50]       [count(ancestor::*)       >=        //*[string-length(normalize-space(.)) > 50]/count(ancestor::*)       ] 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -