开发者

Check contents of div to apply a particular ID

I'm using XSLTs to basically take some basic HTML and implant some CSS so that the resulting file is the original file + the embedded CSS as one single self contained file. No problems so far, all works fine.

However.

Some of my input documents dont have properly formatted div ids, so the CSS I embedded isnt picking up on those items (the input docs come from 4 different providers who all like to do things separately, yay!).

Is there any开发者_如何学C way (js?jquery?) that I can check the text contents of the div for a particular word, and then assign an ID to the div its in? For example, a div should have the ID "Allergies", but if it doesnt, I need to check the div text to look for the word "Allergy", and then assign "Allergies" as the div Id.

Sounds a bit odd I know, but if its possible it would greatly help my ability to get the output documents all conforming to one layout and style.

This is to be displayed on Blackberrys/WinPhones, so the restrictions of those should be taken into account.

Many thanks,

Christian


Why not write code in xslt itself to generate id

<xsl:if test="contains(value, 'Allergy')">
   <xsl:attribute name="id">
      Allergies
   </xsl:attribute>
</xsl:if>

Using jQuery, you need plugin http://plugins.learningjquery.com/textchildren/

$(content).("div").each( function(index) {
   if($(this).textChildren().contains("Allergy")){
      $(this).addClass("Allergies");
   }
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜