Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] absolute [OT]: html tags in xml xsl
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 6:55 am    Post subject: [SOLVED] absolute [OT]: html tags in xml xsl Reply with quote

hallo,

ich möchte mich an dieser Stelle für diesen absolute OT Post entschuldigen. Aber in diversen (topic-bezogenen) anderen Foren bekam ich keine oder nur unzureichende Antworten (und das gentoo-Forum ist einfach das beste).
Es ist so, dass ich gerne html Tags in einer XML Struktur unterbringen möchte.
Code:

<structure>
  <b>fetter text oder nur ein weiterer xml-tag??</b>
</structure>

ich denke an diesem Beispiel sieht man das Problem. Daher: gibts irgendwelche "escape" Sequenzen für HTML in Xml oder einen anderen Trick?
Das ganze wird dann mit einem xsl Template und dem XsltProcessor() von PHP geparst....

danke im voraus!
ciao

PS: wenn dieser Post irgendjemanden störte -> da ist ein netter "back" Button im Browser... :)


Last edited by _hephaistos_ on Wed Aug 11, 2004 8:40 am; edited 1 time in total
Back to top
View user's profile Send private message
leuenberger
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2003
Posts: 147
Location: Zurich, ZH, Schweiz

PostPosted: Wed Aug 11, 2004 7:15 am    Post subject: Re: absolute [OT]: html tags in xml xsl Reply with quote

hephaistos6 wrote:
Daher: gibts irgendwelche "escape" Sequenzen für HTML in Xml oder einen anderen Trick?


Nicht, dass mich Dein Posting stört, aber könntest Du die Sache noch etwas erläutern? Ich habe keinen Schimmer, was Du eigentlich von uns willst...

Gruss Reto
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 7:20 am    Post subject: Reply with quote

hallo,

naja, es muss doch möglich sein zB "<b>text</b>" in eine xml Struktur zu schreiben, sodass dieses dann auch als <b> im Browser wiedergegeben wird... Mir kommt das auch sehr spanisch vor, darum frage ich ja. Ich weiß eben nicht, wie das gehen kann.... aber da XML ja auch zum Daten speichern ist, muss es doch möglich sein, den Text zwischen zwei XML-Tags als "TEXT" zu bezeichnen und nicht, dass dieser auch noch geparst wird.

Ist es so verständlicher? :)

thx
Back to top
View user's profile Send private message
leuenberger
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2003
Posts: 147
Location: Zurich, ZH, Schweiz

PostPosted: Wed Aug 11, 2004 7:36 am    Post subject: Reply with quote

Ich glaube jetzt habe ich Dein Problem kapiert. Ich versuch es mal...

Du hast irgendeine XML-Datei und zeigst diese mit dem Browser an (Welchen Browser verwendet Du? Da gibt es grosse Unterschiede.). Und jetzt wunderst Du Dich, weil der Browser den Text in den <b>-Tags nicht fett schreibt? Ist dass so richtig?

Wenn ja: Du lädst irgendeine XML-Datei in den Browser. Der Browser "sieht" aufgrund der Header-Zeile, dass es kein (X)HTML ist. Woher soll also jetzt der Browser weisse, dass <b> fett bedeutet?
Es gibt zwei Möglichkeiten, wie Du dem Browser mitteilen kannst, dass <b> fett bedeutet usw. Die erste ist einfach, für viele Dinge zu einfach: CSS. Die zweite ist aufwendig, dafür kannst Du fast alles machen: XSLT!
Aber um die beiden kommst Du nicht herum...

Wenn nein: Ich hab es immer noch nicht begriffen. Vielleicht ist es noch etwas zu früh für mich 8)

Gruss Reto
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 7:39 am    Post subject: Reply with quote

hallo,

ja, ich denke du hast kapiert, worum es geht :)

ja, ich transformiere mit XSL (phps interner XsltProcessor()).
das ist auch gar kein Problem, eben bis ich zB ein "FEld" komplett als HTML anzeigen lassen will.
<structure>
<normalerHTMLText>
hier steht normaler html text, welcher nicht interpretiert werden darf!!
</normalerHTMLText>
</structure>

dass der Tag "<normalerHTMLText>" wirklich NUR als Datenfeld interpretiert wird und nicht noch extra geparst wird....
gibts dazu eine spezifikation im XSL?

thx
Back to top
View user's profile Send private message
leuenberger
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2003
Posts: 147
Location: Zurich, ZH, Schweiz

PostPosted: Wed Aug 11, 2004 7:54 am    Post subject: Reply with quote

Das letzte Posting war gut. Jetzt bin ich wirklich dabei :P

Kannst Du noch die entsprechende XSLT-Passage posten? Ich habe etwas Mühe mich in das Problem "einzudenke". Es ist eben immer noch etwas früh :o

Gruss Reto
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 7:58 am    Post subject: Reply with quote

ok: hier das xml
Code:

<?xml version="1.0" encoding="UTF-8"?>
<content>
   <paragraph>
      <b>hier steht html in fett :)</b>
   </paragraph>
</content>

und das xsl:
Code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="no" />
   <xsl:template match="content">
      <xsl:value-of select="paragraph" />
   </xsl:template>
</xsl:stylesheet>


danke für deine bemühung mir zu folgen :)
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 8:00 am    Post subject: Reply with quote

aber wie ich gerade sehe, scheint das nicht möglich zu sein.
ich müsste für jedes element, welches ich als html anzeigen will einfach eine stylesheetdefinition schreiben... vielleicht schreib ich mir so ein stylesheet mit den gängigsten html tags.
aber was ist zB mit <div style="text-align:center"> dafür kann ich ja schlecht eine stylesheetdefinition schreiben oder?

thx
Back to top
View user's profile Send private message
leuenberger
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2003
Posts: 147
Location: Zurich, ZH, Schweiz

PostPosted: Wed Aug 11, 2004 8:36 am    Post subject: Reply with quote

Darum wirst Du wohl nicht herum kommen. Ich würde Dir aber empfehlen in der xml-Datei zu verweden. Sonder wirklih selber diefinierte Namen:

XML-Datei
Code:
<content>
   <paragraph>
      <mybold>hier steht html in fett :)</mybold>
      <mycenter>hier steht html in der Mitte :)</mycenter>
   </paragraph>
</content>


XSLT-Datei
Code:
<xsl:output method="html" />

<xsl:template match="/">
   ...
   <xsl:apply-templates match="content/paragraph" />
   ...
</xsl:template>

<xsl:template match="paragraph">
   ...
   <xsl:apply-templates match="mybold" />
   <xsl:apply-templates match="mycenter" />
   ...
</xsl:template>


<xsl:template match="mybold">
   <b>
      <xsl:value-of select="." />
   </b>
</xsl:template>

<xsl:template match="mycenter">
   <div style="text-align:center">
      <xsl:value-of select="." />
   </div>
</xsl:template>


Ich habe den Code nicht getestet. Aber ich denke, so würde ich das Problem lösen... Was meinst DU?

Gruss Reto
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 8:39 am    Post subject: Reply with quote

ja, so gehts auf alle fälle.
nur ich hab mir gedacht, es gäbe einen "einfacheren" weg .)

aber danke für deine hilfe!
Back to top
View user's profile Send private message
leuenberger
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jul 2003
Posts: 147
Location: Zurich, ZH, Schweiz

PostPosted: Wed Aug 11, 2004 8:47 am    Post subject: Reply with quote

XSLT ist in der Regel nicht einfach :!:
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 8:53 am    Post subject: Reply with quote

ehrlich gesagt: ich arbeite erst seit 2 tagen damit und finde es nicht schwierig. ich finde es sehr flexibel und umfangreich... bisher hat man immer "templates" mit irgendwelchen "patterns" verwendet, die dann durch inhalte ersetzt wurden (zB die PHP Klasse Smarty) -> aber XSL find ich viel besser :) vor allem, weil es durch apache bzw. div. libraries geparst wird und nicht durch eine "schwindlige" PHP Klasse...

thx,
ciao
Back to top
View user's profile Send private message
rockhead
Tux's lil' helper
Tux's lil' helper


Joined: 18 Feb 2004
Posts: 105
Location: wonderland

PostPosted: Wed Aug 11, 2004 10:52 am    Post subject: Reply with quote

hallo hephaistos6,

die lösung deines problems (hoffentlich habe ich es richtig verstanden) liegt in der verwendung von namespaces.
du brauchst zwei unterschiedliche namespaces. einen für den html-markup und einen für deine eigene markup-sprache.
das sieht dann so aus (exemplarisch!)

Code:
<my:content xmlns:html="http://www.w3.org/1999/xhtml" xmlns:my="http://mynamespace">
   <my:paragraph>
      <html:p>paragraph</html:p>
   </my:paragraph>
</my:content>

Code:
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:my="http://mynamespace"
   xmlns:html="http://www.w3.org/1999/xhtml">

   <!-- dokumentwurzel -->
   <xsl:template match="/">
      <html:html>
         <xsl:apply-templates/>
      </html:html>
   </xsl:template>
   
   <!-- behandelt das element content aus dem namensraum my -->
   <xsl:template match="my:content">   
      <html:body>   
         <xsl:apply-templates/>
      </html:body>
   </xsl:template>
   
   <!-- behandelt beliebiges element aus dem namensraum html -->
   <xsl:template match="html:*">      
         <xsl:copy-of select="."/>      
   </xsl:template>   
   
   <!-- nicht behandelte elemente/attribute/text ignorieren -->   
   <xsl:template match="*|@*|text()">      
         <xsl:apply-templates/>      
   </xsl:template>
</xsl:stylesheet>
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 11:09 am    Post subject: Reply with quote

hi rockhead

das wäre eine tolle idee, aber mein XsltProcessor wirft immer folgenden Fehler aus:

Code:

Namespace prefix my on content is not defined in /<pfad>/file.xml


weißt du, was ich da tun kann?

thx,
ciao
Back to top
View user's profile Send private message
rockhead
Tux's lil' helper
Tux's lil' helper


Joined: 18 Feb 2004
Posts: 105
Location: wonderland

PostPosted: Wed Aug 11, 2004 11:13 am    Post subject: Reply with quote

welchen xsltprozessor verwendest du denn?
bei mir klappt es mit xalan (java) und xsltproc frisst es auch
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 11:16 am    Post subject: Reply with quote

hmmm XsltProcessor mit mod_php-5.0.0...

Code:

$proc = new XsltProcessor();
$xmlObject = new DomDocument();
$xmlObject->load("file.xml");

$xslObject = new DomDocument();
$xslObject->load("file.xsl");

$proc->importStyleSheet($xslObject);
echo $proc->transformToXML($xmlObject);
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 11:25 am    Post subject: Reply with quote

aha! jetzt gehts ohne fehler, aber bold is es auch nicht.
ich werd mir das anschauen. danke für die info! bin noch neu bei xsl :)
Back to top
View user's profile Send private message
rockhead
Tux's lil' helper
Tux's lil' helper


Joined: 18 Feb 2004
Posts: 105
Location: wonderland

PostPosted: Wed Aug 11, 2004 11:37 am    Post subject: Reply with quote

hmm, bei dieser transformation kann nix in bold rauskommen, denn ich habe eigenmächtig das <b>-tag gegen ein <p>-tag ausgetauscht :wink:
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 11:42 am    Post subject: Reply with quote

sorry - schlecht ausgedrückt. html code kommt so raus:
Code:

<?xml version="1.0"?>
<html:html xmlns:html="http://www.w3.org/1999/xhtml" xmlns:my="http://mynamespace">
   <html:body><html:b>paragraph</html:b></html:body>
</html:html>


und da is nix bold... bzw. <p> :)

thx again
Back to top
View user's profile Send private message
rockhead
Tux's lil' helper
Tux's lil' helper


Joined: 18 Feb 2004
Posts: 105
Location: wonderland

PostPosted: Wed Aug 11, 2004 11:59 am    Post subject: Reply with quote

um "reinen" html-code zu bekommen, kannst du in einem weiteren transformationsschritt die namespaces wieder entfernen.
folgendes stylesheet entfernt alles überflüssige:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="*">
      <!-- remove element prefix (if any) -->
      <xsl:element name="{local-name()}">
        <!-- process attributes -->
        <xsl:for-each select="@*">
          <!-- remove attribute prefix (if any) -->
          <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates/>
      </xsl:element>
  </xsl:template>
</xsl:stylesheet>
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 12:07 pm    Post subject: Reply with quote

@rockhead: danke danke danke :) es wird IMMER BESSER.... und auch ich :)

nur eines noch:
aus
Code:

<my:content  xmlns:html="http://www.w3.org/1999/xhtml" xmlns:my="http://www.w3.org/1999/xhtml">
   <html:b>paragraph</html:b><html:br />lkdsajldsdsajkf
</my:content>


erhalte ich jetzt:
Code:

<content>
   <b>paragraph</b><br/>lkdsajldsdsajkf
</content>


wie bring ich die <content> am saubersten weg?
Back to top
View user's profile Send private message
rockhead
Tux's lil' helper
Tux's lil' helper


Joined: 18 Feb 2004
Posts: 105
Location: wonderland

PostPosted: Wed Aug 11, 2004 12:11 pm    Post subject: Reply with quote

du musst beide transformationen anwenden:
xml-->xsl1-->xsl2-->html
wird dich vielleicht zunächst wundern, aber es ist durchaus üblich mehrere transformationen durchzuführen um das gewünschte ergebnis zu bekommen
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 12:17 pm    Post subject: Reply with quote

hallo,

ok, dann werd ich mir das mal durch den kopf gehen lassen...
momentan worked es noch nicht - aber ich werd schon draufkommen...

danke für deinen einsteigerkurs!

ciao
Back to top
View user's profile Send private message
rockhead
Tux's lil' helper
Tux's lil' helper


Joined: 18 Feb 2004
Posts: 105
Location: wonderland

PostPosted: Wed Aug 11, 2004 12:26 pm    Post subject: Reply with quote

oh oh, ich kann doch gar kein php :cry:

aber so ähnlich könnte es aussehen:

Code:
$proc = new XsltProcessor();
$xmlObject = new DomDocument();
$xmlObject->load("file.xml");

$xsl1Object = new DomDocument();
$xsl1Object->load("file.xsl");

$xsl2Object = new DomDocument();
$xsl2Object->load("strip.xsl");

$proc->importStyleSheet($xsl1Object);
$xmlObject = $proc->transformToXML($xmlObject);

$proc->importStyleSheet($xsl2Object);
echo $proc->transformToXML($xmlObject);
Back to top
View user's profile Send private message
_hephaistos_
Advocate
Advocate


Joined: 07 Apr 2004
Posts: 2694
Location: salzburg, austria

PostPosted: Wed Aug 11, 2004 3:22 pm    Post subject: Reply with quote

hallo,

nein, so gehts sicher nicht, da $object->transformToXml($xmlobject) einen string zurückliefert...

ich spiel mich jetzt mal damit und sag dir dann bescheid...

ciao
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum