|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm not used to DTD, and in this case I think this is easier this way: I'm showing here a lame layout of how my XML is. Imagine it's well-formatted XML
![]() Code:
<documents>
<page>
<html>
<head>
<style>.styleOne {color:#FF0000}<style>
</head>
<body>
<font class="styleOne">Hi</font>
</body>
</html>
</page>
<page>
<html>
<head>
<style>.styleOne {color:#0000FF}<style>
</head>
<body>
<font class="styleOne">Hi</font>
</body>
</html>
</page>
</documents>
Then, my XSL should produce something like this: Hi Hi If I use Code:
<xsl:for-each select="page"> <xsl:copy-of select="page"/> <br/> </xsl:for-each> It produces Hi Hi and it will not work on IE6 anyway (the first </html> will close the entire page) If instead I use Code:
<xsl:for-each select="page//body/*"> <xsl:copy-of select="page"/> <br/> </xsl:for-each> It will produce Hi Hi Because it hasn't had the Styles. Does anyone know how to solve this? |
|
#2
|
||||
|
||||
|
it has the styles, check your well formedness as well as your style names.
PHP Code:
and PHP Code:
worked just right for me
__________________
Teflon - The Black <desc>Mark This Up</desc> |
|
#3
|
|||
|
|||
|
I'd provide another answer than Teflon's (no offense
). Actually, XML + XSL is supposed to turn into ONE html file, therefore you're only supposed to have the <html> tag (as well as <head> and <body>) only once in the resulting file. So my suggestion would be to change the way you structure your files, I'd rather make something like this: Code:
<documents>
<page>
<style>.styleOne {color:#FF0000}</style>
<font class="styleOne">Hi</font>
</page>
<page>
<style>.styleTwo {color:#0000FF}</style>
<font class="styleTwo">Hi</font>
</page>
</documents>
and this into xsl: Code:
<xsl:template match="documents">
<html>
<head>
<style>
<xsl:apply-templates select="//style" />
</style>
</head>
<body>
<xsl:apply-templates select="//font" />
</body>
</html>
</xsl:template>
<xsl:template match="font">
<font class="{@class}">
<xsl:value-of select="text()" />
</font>
</xsl:template>
Hope this helps. |
|
#4
|
||||
|
||||
|
Very good point kid23.
|
|
#5
|
|||
|
|||
|
I know that the structure is not the best ever, but "no can't don't"
The XML source and its DTD are not on reach of my greedy hands. Sometimes you have to be user-compliant instead of standard-compliant. ![]() Most of the <page> elements contain HTML with the styles applied the "inline" way, because they come from a rich text editor and with those the second way I wrote works just fine. But sometimes instead of using the editor the users import an HTML file or copy&paste from that horrible Word 2000 and that's the way I get that kind of structure. Thanks anyway, I will post if I find it. |
|
#6
|
|||
|
|||
|
Ow.. I see.. then, if you can't get rid of this structure, you can still use my solution, but you have to adjust it a little.
First, the fact that the main html tags may appear only once is still valid, so you need to keep them written by the template of your root element. To make sure they don't get processed, you should write empty templates for them, something like this: <xsl:template match="html | head | body" /> That would do the same as the solution I had proposed, but without having to remove your tags. I'm not even sure that writing an empty translation rule is mandatory.. but you should give it a try. Let me know how it works. ![]() |
|
#7
|
|||
|
|||
|
Thanks Kid23, I'll keep you posted.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > How to avoid to CSS styles to "collide" |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|