Announcement

Collapse
No announcement yet.

Verständnisprob. mit konkretem Trafo-Ergebnis

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Verständnisprob. mit konkretem Trafo-Ergebnis

    Hallo zusammen,

    ich versuche seit einer Weile diese Transformation hinzubekommen. Sie soll eine Art Filter darstellen zur Vorbereitung auf die nächste Transformation. Leider erscheint im Ergebnis immer diese Rollenbezeichnung unterhalb und ich hab keinen blassen Schimmer warum die da hingesetzt wird.

    profile.xml:

    <site>
    <profile>
    <person name="Max Mustermann">
    <address street="Msstrasse." number="27" city="Berlin" country="Germany"/>
    <birthday day="12" month="12" year="1982" city="Berlin" country="Germany"/>
    <homepages>
    </homepages>
    <role name="Besitzer"/>
    <resume>
    <jobs>
    <job type="education">
    <period>
    <from day="" month="" year=""/>
    <to day="" month="" year=""/>
    </period>
    <institution name="Some Institution">
    <address>
    </address>
    </institution>
    </job>
    </jobs>
    </resume>
    <projects>
    </projects>
    </person>
    </profile>
    <members>
    <person name="Martin Mustermann">
    <address street="Msstrasse." number="" city="Berlin" country="Germany" />
    <birthday day="11" month="11" year="1983" city="Berlin" country="Germany" />
    <homepages>
    <site url="http://www.atestlink1.de" />
    <site url="http://www.atestlink2de" />
    </homepages>
    <role>Management</role>
    </person>
    </members>
    </site>
    fltr.xsl:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

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

    <xsl:template match="/profile">
    <profile>
    <xsl:apply-templates match="site/profile/person"/>
    </profile>
    </xsl:template>

    <xsl:template match="/profile/person">
    <person>
    <xsl:attribute name="name">
    <xsl:value-of select="@name"/>
    </xsl:attribute>
    </person>
    </xsl:template>


    </xsl:stylesheet>
    Das Ergebnis sieht etwa so aus:

    <profile>
    <person name="Max Mustermann">
    </person>
    </profile>

    Management
    Ich transformiere mit der xsllib von PHP (Version müsste ich noch herraussuchen, falls das hierfür eine Rolle spielen sollte).

    Wäre interessant wenn mir jemand erklären könnte wie es zu diesem Ergebnis kommt, da ich ja nirgends explizit diese Rolle einfüge.

    Viele Grüße,
    Felix

  • #2
    jede Transformation sollte
    mit
    xsl:template match="/"
    ist der Dokument root


    mit xsl:apply-templates / werden alle knoten angesprochen

    ich beginne immer von unten nach oben
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    	<xsl:output indent="yes" method="xml"/>
    	<xsl:template match="/">
    		<xsl:apply-templates select="site"/>
    	</xsl:template>
    	<xsl:template match="site">
    		<xsl:apply-templates select="profile"/>
    	</xsl:template>
    	<xsl:template match="/profile">
    		<profile>
    			<xsl:apply-templates match="person"/>
    		</profile>
    	</xsl:template>
    
    	<xsl:template match="person">
    		<person>
    			<xsl:attribute name="name">
    				<xsl:value-of select="@name"/>
    			</xsl:attribute>
    		</person>
    	</xsl:template>
    </xsl:stylesheet>
    Vorstellenung match ist der Tagname und das template
    beschreibt wie die veränderung stattfindet
    welche Wert benutzt werden und in welcher Reihen folge
    sie ausgeben werden

    Comment


    • #3
      Verständnisprob. mit konkretem Trafo-Ergebnis

      Hallo,

      vielen Dank für den Tipp, jetzt tuts auf jeden Fall. Man muss wohl immer vom Wurzelelement den ersten Knoten auswählen sonst bleibt man evtl. in einer Schleife oder bekommt solche merkwürdigen Effekte wie ich sie hatte.

      Gruß,
      Felix

      Comment


      • #4
        ich meine es lag daran dass es kein Template für role gab.
        Hättest du in deinem xsl ein leeres role-template erstellt wäre es vermutlich gegangen.
        gruß
        sth_Weird
        Fluchen ist die einzige Sprache, die jeder Programmierer perfekt beherrscht

        Comment


        • #5
          Stimmt, das könnte sein. Leider übersieht man (oder zumindest ich) solche Dinge leicht. Hilfreich wäre da ein Editor der schonmal solche häufigen Fehler mit Warnhinweisen aufdeckt. Mal sehen obs dazu bei Google was gibt..
          Verwende zur Zeit noch den normalen XML-Editor von Eclipse.

          Bis dahin,
          Felix

          Comment

          Working...
          X