Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Annotating/marking/labeling text inside XML

Status
Not open for further replies.

noblends

Programmer
Jun 8, 2006
6
FR
Hi. A quick thanks to those who try to help. here's what i'm trying to do:

<?xml>
<stuff>
<theStory>

<p>aaklsjd fakljs fakjs faskldj a;klsjdf l;aksdj f THIS TEXT SHOULD BE HIGHLIGHED a;klsdjf a;slkjdf a;skljdf a;slkjdf a;slkjf a;sklj fas;kl jf;ak s</p>

<p> askljdf laksjdf ;alksjdf a;skljdf ;askldjf; askdlfj ;sdlkfj THIS TEXT SHOULD ALSO BE HIGHLIGHTED alksjdf a;klsjfd a;slkdfja s;dfkjas; dfaklsjd f</p>

</theStory>
</stuff>

so my question is how can i somehow mark up the text in the xml so as to be able to treat it later via CSS?

Thanks,
eric
 
Why not simply do such as this?...
[tt]
<p>aaklsjd fakljs fakjs faskldj a;klsjdf l;aksdj f <highlight>THIS TEXT SHOULD BE HIGHLIGHED</highlight> a;klsdjf a;slkjdf a;skljdf a;slkjdf a;slkjf a;sklj fas;kl jf;ak s</p>

<p> askljdf laksjdf ;alksjdf a;skljdf ;askldjf; askdlfj ;sdlkfj <highlight>THIS TEXT SHOULD ALSO BE HIGHLIGHTED</highlight> alksjdf a;klsjfd a;slkdfja s;dfkjas; dfaklsjd f</p>
[/tt]
and with the style in css.
[tt]
highlight {
background:yellow;
color:red;
}
[/tt]
 
Surface inspection of your xml,
>type="text/xsl"
[tt]type="text/css"[/tt]

 
>...so as to be able to treat it later via CSS?
Make a href point to .css file with only context I posted for instance.

 
i don't think that will work - the xml stylesheet has to have the content type "text/xml" like so:

<?xml-stylesheet type="text/xsl" href="stuff.xsl?"?>

otherwise it won't be processed as xsl. there's got to be some way of marking the text inside xml so that it can be processed as by an xsl stylesheet.

any other ideas?
 
Then you should not say "to treat it later via CSS". You could do more in formating you like if you use xsl. But do you think xsl is css?
 
the question is how to denote, or mark, small strings of text that fall within larger strings of text in xml.

as we know, one of the major benefits to using an xml/xsl/css solution is that content is almost entirely separated from markup. the content gets stored in xml and the markup is treated w/ a combination of xsl/css. but what happens when we need to do just a little bit of markup in xml? like my example:

<greatStory>
<chapter1>
<p>once upon a time <highlight>something great happened</highlight> and everybody was happy for a long time.</p>
</chapter1>
</greatStory>

this won't work for reasons described above - essentially because XSL stops processing the text once it reaches the <highlight> tag.

in addition, declaring the accompanying xsl stylesheet to be of type "text/css" doesn't work either because then the xml isn't processed by xsl.

i wrote "to be treated by CSS later" just as a way of further describing what my end goals were. essentially i just need a way to pick up that highlighted text.

now that i think about it, what i probably should have written is:

<p>once upon a time <span class="highlight">something great happened</span> and everybody was happy for a long time.</p>

which also doesn't work (XSL processor stops processing the line upon encountering the <span class="highlight"> tag) but maybe that will clear it up what i'm trying to do.

thanks.
 
[1] xml
[tt]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stuff.xsl"?>

<stuff>
<theStory>

<p>para1 para1 para1 para1 <highlight>THIS TEXT SHOULD BE HIGHLIGHED</highlight> para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 para1 </p>

<p>para2 para2 para2 para2 para2 para2 <highlight>THIS TEXT SHOULD ALSO BE HIGHLIGHTED</highlight> para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 para2 </p>

</theStory>
</stuff>
[/tt]
[2] stuff.xsl
[tt]
<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="stuff/theStory/p">
<p>
<xsl:value-of select="text()" />
<xsl:apply-templates />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="highlight">
<span style="background:yellow;color:red;"><xsl:value-of select="." /></span>
</xsl:template>
</xsl:stylesheet>
[/tt]
You get plenty of freedom and you would say I would do this and do that.

One reason you mark up in the xml for mixed content node is precisely it helps those who read it get a meaning semantically rather than no marking it up. As to what precisely it will show up in the rendering is cutoff from that semantic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top