XSL-Transformation erzeugt Output obwohl keiner erzeugt werden soll

guni

Bekanntes Mitglied
Hallo,

stehe vor einem seltsamen Problem.
ich habe eine XML-Datei:

[XML]<?xml version="1.0"?>
<xmap-content version="2.0" xmlns="urn:xmind:xmap:xmlns:content:2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
<sheet id="05kogoti6q7p7o552qqnk9msp4">
<topic id="5mc1923l0om840hk45jpogkako" timestamp="1277382542303">
<title>Berufsbilder</title>
<children>
<topics type="attached">
<topic id="04taqi0s7tg0ar6f72bqqhlfac" timestamp="1277298961641">
<title>EDV-Techniker</title>
<children>
<topics type="attached">
<topic id="75oo7lm1m0luv1efthj5rarvs1" timestamp="1277298455030">
<title>1.1.1</title>
<children>
<topics type="attached">
<topic id="681on2rui88a2hvbcot0n5sgu1" timestamp="1277298489678">
<title>Einführung in die Aufgaben des Betriebes (Branchenstellung, Erzeugungsprogramm, Dienstleistungsprogramm, Vertriebsprogramm)</title>
</topic>
</topics>
</children>
</topic>
<topic id="554184evsj9jmurbbrov0blgon" timestamp="1277298511098">
<title>1.1.2</title>
</topic>
<topic id="15sahrvg9jbh7th4udulhc3bb2" timestamp="1277298520453">
<title>1.1.3</title>
</topic>
<topic id="3nu5g40ag686o5r51b5tv6ni1g" timestamp="1277298523368">
<title>1.1.4</title>
</topic>
<topic id="34k224no0e3d5572u5gbe84o15" timestamp="1277298534079">
<title>1.2.1</title>
</topic>
<topic id="501jlev4idt2964fdjn802aejc" timestamp="1277298545739">
<title>1.2.2</title>
</topic>
<topic id="33t5dfmt496n7rbj9m6j89h30t" timestamp="1277298553804">
<title>1.2.3</title>
</topic>
<topic id="1oprlfj1qp85cesmm4pht5kcqa" timestamp="1277298556996">
<title>1.2.4</title>
</topic>
<topic id="0l3us2a7fd2165ltthr2a83285" timestamp="1277298559776">
<title>1.2.5</title>
</topic>
<topic id="5as551h72otb3mas7ikq2ea4m2" timestamp="1277298598369">
<title>1.3.1</title>
<children>
<topics type="attached">
<topic id="3gvtqp68pjms7uqs0rn6qv02t3" timestamp="1277298890430">
<title>Kenntnis der sich aus dem Lehrvertrag ergebenden Verpflichtungen (§§ 9 und 10 des Berufsausbildungsgesetzes)</title>
<children>
<topics type="attached">
<topic id="0vbraigmt7j4lpckg9c892i4ja" timestamp="1277298895993">
<title>Recht</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="5ucs0ucl169d8ogp0q6h80kut4" timestamp="1277298630814">
<title>1.3.2</title>
<children>
<topics type="attached">
<topic id="6t9arbstq8q702lq0dm7dg95iu" timestamp="1277298630809">
<title>Kenntnis über Inhalt und Ziel der Ausbildung sowie über wesentliche einschlägige Weiterbildungsmöglichkeiten</title>
</topic>
</topics>
</children>
</topic>
<topic id="3nk81hvkdvmsoh3qheaknadkhn" timestamp="1277298660099">
<title>1.3.3</title>
<children>
<topics type="attached">
<topic id="464huvc57o2q616ia4u70064lq" timestamp="1277298660094">
<title>Kenntnis über Arbeitsorganisation und Arbeitsgestaltung, Teamarbeit und Projektarbeit</title>
</topic>
</topics>
</children>
</topic>
<topic id="0i3llnqh7tscao41fn51m1cpnt" timestamp="1277298946907">
<title>1.3.4</title>
</topic>
<topic id="6tl8u51dkdueloq19os60ej7qd" timestamp="1277298988547">
<title>2.1.1</title>
<children>
<topics type="attached">
<topic id="5oc28tl1tbv1pij2arhtgong8d" timestamp="1277455410796">
<title>Kenntnis über Hardware und Software, Peripherie, Betriebssysteme und Anwenderprogramme</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="3p0nus0bqlbp1eefpeodfse5pe" timestamp="1277382561143">
<title>Kommunikationstechniker</title>
</topic>
</topics>
</children>
</topic>
<title>Arbeitsblatt 1</title>
</sheet>
</xmap-content>[/XML]

sieht nicht kompliziert aus, oder?!
jetzt will ich sie so umwandeln, dass ich sie dann in Excel einlesen kann.

Habe mal eine "leere" XSL-Datei:
[XML]<?xml version="1.0"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:eek:utput
method="xml"
version="1.0"
encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="/test/sheet/topic/children">
</xsl:template>


</xsl:stylesheet>[/XML]
mein erwartetes Ergebnis wäre vorläufig mal ... NICHTS!

Mein Ergebnis sieht aber so aus:
[XML]<?xml version="1.0" encoding="iso-8859-1"?>BerufsbilderEDV-Techniker1.1.1Einf�hrung in die Aufgaben des Betriebes (Branchenstellung, Erzeugungsprogramm, Dienstleistungsprogramm, Vertriebsprogramm)1.1.21.1.31.1.41.2.11.2.21.2.31.2.41.2.51.3.1Kenntnis der sich aus dem Lehrvertrag ergebenden Verpflichtungen (�� 9 und 10 des Berufsausbildungsgesetzes)Recht1.3.2Kenntnis �ber Inhalt und Ziel der Ausbildung sowie �ber wesentliche einschl�gige Weiterbildungsm�glichkeiten1.3.3Kenntnis �ber Arbeitsorganisation und Arbeitsgestaltung, Teamarbeit und Projektarbeit1.3.42.1.1Kenntnis �ber Hardware und Software, Peripherie, Betriebssysteme und AnwenderprogrammeKommunikationstechnikerArbeitsblatt 1[/XML]

... das wirkt für mich so, als würde der Parser einfach ALLE Text-Nodes herausschreiben! Wieso tut er das?!
Wie kann ich das verhindern?! Das will ich doch gar nicht!

mfg, guni
 

Niki

Top Contributor
du musst den Namespace im xslt auch deklarieren und bei den Tags verwenden. dieses hier funktioniert:

Java:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:xmind:xmap:xmlns:content:2.0" xmlns:tns="urn:xmind:xmap:xmlns:content:2.0">
    
    <xsl:output 
        method="xml"
        version="1.0"
        encoding="iso-8859-1" 
        indent="yes"/>
    
    <xsl:template match="/tns:xmap-content">    
    	<xsl:value-of select="tns:sheet/@id"/>
    </xsl:template>

        
 
</xsl:stylesheet>
 

guni

Bekanntes Mitglied
Hallo,

das verstehe ich nicht ganz.
Ja. Niki hat recht. Sein Stylesheet funktioniert.

Ich wollt es jetzt aber wieder ein bisschen weiter ausbauen:
[XML]
<?xml version="1.0"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:xmind:xmap:xmlns:content:2.0"
xmlns:tns="urn:xmind:xmap:xmlns:content:2.0">

<xsl:eek:utput
method="xml"
version="1.0"
encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="/tns:xmap-content/sheet/topic/children/topics">
<excel>
<xsl:for-each select="tns:topic">
<test>TEST</test>
</xsl:for-each>
</excel>
</xsl:template>

</xsl:stylesheet>
[/XML]

das geht dann schon wieder nicht mehr!
ich versteh das nicht!
und muss ich da jetzt immer ein tns davor schreiben?!
wofür steht tns überhaupt.

ich dachte immer, der einzige sinn von namespaces ist, dass ich gleichnamige tags verschiedener bedeutung in einem xml verwenden kann. also warum muss ich sie dann anführen wenn ich die tag-Namen im endeffekt eh nicht mehrfach belege?!

mfg, guni

PS.: wenn ich das TNS im for-each weglasse geht es auch nicht ...
 

Niki

Top Contributor
ich würds so machen:
Java:
<?xml version="1.0"?>
<xsl:stylesheet 
    version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"   
    xmlns:tns="urn:xmind:xmap:xmlns:content:2.0"
    exclude-result-prefixes="tns">
    
    <xsl:output 
        method="xml"
        version="1.0"
        encoding="iso-8859-1" 
        indent="yes"/>
        
        <xsl:template match="/">
        	<xsl:apply-templates select="tns:xmap-content/tns:sheet/tns:topic/tns:children/tns:topics"></xsl:apply-templates>
        </xsl:template>
    
    <xsl:template match="tns:topics">
        <excel>
            <xsl:for-each select="tns:topic">
                <test>TEST</test>
            </xsl:for-each>
        </excel>
    </xsl:template>
 
</xsl:stylesheet>
 

guni

Bekanntes Mitglied
hey ... jetzt muss ich euch nochmal kurz nerven
und zwar hab ich noch folgendes Problem:

ich hab einen topic-Baum:

[XML]<children>
<topics type="attached">
<topic id="2d38cnrbrcb7a7fmvsall2tgrv" timestamp="1277456449330">
<title>Stempeluhr / Consens</title>
</topic>
<topic id="0hb8frl3cbmre4n6e9p3l4cbrt" timestamp="1277456449333">
<title>Arbeitszeiterfassung</title>
</topic>
<topic id="423m0sebvv2jk43v4ivk2iaj07" timestamp="1277456449337">
<title>Urlaubsanträge, Zeitkorrekturen</title>
</topic>
<topic id="27i1vjohkhov3f6re42047getd" timestamp="1277456449340">
<title>Verhalten im Brandfall, Rettungsübungen, ...</title>
</topic>
<topic id="1qu09dva43bq3kllolq839t1i9" timestamp="1277456449344">
<title>Krankenstand wo melden</title>
</topic>
<topic id="7a3ufhpk7g50igfdqk8hc3ht6i" timestamp="1277463866123">
<title>Autopool</title>
<children>
<topics type="attached">
<topic id="1g40766sul7h138tc3btug0vrs" timestamp="1277463871665">
<title>Durchwahl von Elisabeth</title>
</topic>
</topics>
</children>
</topic>
<topic id="0q16s6on5sa7a3t269nccd1iv5" timestamp="1277456449388">
<title>interne EDV - Richtlinien</title>
</topic>
</topics>
</children>[/XML]

ich will ihn so umwandeln, dass eine HTML-Gliederung herauskommt.
also irgendwas in die Richtung
[XML]
<ul>
<li>THEMA1</li>
<li>THEMA2
<ul>
<li>UNTERTHEMA2.1</li>
<li>UNTERTHEMA2.2</li>
<li>UNTERTHEMA2.3</li>
</ul>
</li>
<li>THEMA3</li>
<li>THEMA4</li>
<li>THEMA5</li>
</ul>
[/XML]

mein Problem is: ich weiß nicht, wie tief die topics verschachtelt sind!
gibt es da in xsl irgendeine rekursive lösung?!

mfg, guni
 

guni

Bekanntes Mitglied
ich glaub ich habs :D

[XML] <xsl:template name="tree">
<xsl:for-each select="tns:children/tns:topics/tns:topic">
<li>
<xsl:value-of select="tns:title"/>
<xsl:if test="current()/tns:children/tns:topics/tns:topic">
<ul>
<xsl:call-template name="tree"/>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</xsl:template>[/XML]
 

guni

Bekanntes Mitglied
Hallo,

jetzt habe ich das gleiche Problem schon wieder: ich bekomme Output der eigentlich nicht da sein sollte!
also: hier mein XML:

[XML]<?xml version="1.0"?>
<xmap-content version="2.0" xmlns="urn:xmind:xmap:xmlns:content:2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
<sheet id="05kogoti6q7p7o552qqnk9msp4">
<topic id="5mc1923l0om840hk45jpogkako" timestamp="1277456975599">
<title>Berufsbilder</title>
<children>
<topics type="attached">
<topic id="04taqi0s7tg0ar6f72bqqhlfac" timestamp="1277457253457">
<title>EDV-Techniker</title>
<children>
<topics type="attached">
<topic id="2r8oq63clb3nvfmq1q3ob52c2r" timestamp="1277457102166">
<title>1. Der Lehrbetrieb</title>
<children>
<topics type="attached">
<topic id="2v9q4vnl5jld39gbqcp0auvqot" timestamp="1277457028633">
<title>1.1 Wirtschaftliche Stellung des Lehrbetriebes</title>
<children>
<topics type="attached">
<topic id="75oo7lm1m0luv1efthj5rarvs1" timestamp="1277457026477">
<title>1.1.1</title>
<children>
<topics type="attached">
<topic id="681on2rui88a2hvbcot0n5sgu1" timestamp="1277457014721">
<title>Einführung in die Aufgaben des Betriebes (Branchenstellung, Erzeugungsprogramm, Dienstleistungsprogramm, Vertriebsprogramm)</title>
</topic>
</topics>
</children>
</topic>
<topic id="554184evsj9jmurbbrov0blgon" timestamp="1277457026484">
<title>1.1.2</title>
<children>
<topics type="attached">
<topic id="0evjjn2gkcbqmojg475giitlpq" timestamp="1277457014713">
<title>Kenntnis des organisatorischen Aufbaus sowie der Aufgaben und Zuständigkeiten der einzelnen Betriebsbereiche</title>
</topic>
</topics>
</children>
</topic>
<topic id="15sahrvg9jbh7th4udulhc3bb2" timestamp="1277457026490">
<title>1.1.3</title>
<children>
<topics type="attached">
<topic id="0e38ogoidhec1ppga2ieli4dqp" timestamp="1277457014703">
<title>Kenntnis der Marktposition, des Kundenkreises, mit seinen Einkaufsgewohnheiten sowie des Kundenverhaltens</title>
</topic>
</topics>
</children>
</topic>
<topic id="3nu5g40ag686o5r51b5tv6ni1g" timestamp="1277457026498">
<title>1.1.4</title>
<children>
<topics type="attached">
<topic id="0oh31m1mgfu102hl0mf01nnekg" timestamp="1277457014692">
<title>Kenntnis der Betriebsform und der Rechtsform des Lehrbetriebes</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="74apohj196cqn2p70tovcuu9qf" timestamp="1277457088306">
<title>1.2 Einrichtungen, Arbeitssicherheit, Unfallverhütung</title>
<children>
<topics type="attached">
<topic id="34k224no0e3d5572u5gbe84o15" timestamp="1277457085739">
<title>1.2.1</title>
<children>
<topics type="attached">
<topic id="1m2f8lca8cug3nrjh9rb6eubem" timestamp="1277463925369">
<title>Kenntnis und funktionsgerechte Anwendung der betrieblichen Einrichtungen und der technischen Betriebsmittel und Hilfsmittel</title>
<children>
<topics type="attached">
<topic id="5hr0jmj13lk6nnh3h3a30pdmlk" timestamp="1277456449392">
<title>1</title>
<children>
<topics type="attached">
<topic id="2d38cnrbrcb7a7fmvsall2tgrv" timestamp="1277456449330">
<title>Stempeluhr / Consens</title>
</topic>
<topic id="0hb8frl3cbmre4n6e9p3l4cbrt" timestamp="1277456449333">
<title>Arbeitszeiterfassung</title>
</topic>
<topic id="423m0sebvv2jk43v4ivk2iaj07" timestamp="1277456449337">
<title>Urlaubsanträge, Zeitkorrekturen</title>
</topic>
<topic id="27i1vjohkhov3f6re42047getd" timestamp="1277456449340">
<title>Verhalten im Brandfall, Rettungsübungen, ...</title>
</topic>
<topic id="1qu09dva43bq3kllolq839t1i9" timestamp="1277456449344">
<title>Krankenstand wo melden</title>
</topic>
<topic id="7a3ufhpk7g50igfdqk8hc3ht6i" timestamp="1277463866123">
<title>Autopool</title>
<children>
<topics type="attached">
<topic id="1g40766sul7h138tc3btug0vrs" timestamp="1277467954331">
<title>Durchwahl von Elisabeth</title>
<children>
<topics type="attached">
<topic id="4s7pe3tjbc30sjukqfilragttp" timestamp="1277467956402">
<title>1234</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="0q16s6on5sa7a3t269nccd1iv5" timestamp="1277456449388">
<title>interne EDV - Richtlinien</title>
</topic>
</topics>
</children>
</topic>
</topics>
<topics type="summary">
<topic id="7nmpqo10jakmicd9foi9jpasbs" timestamp="1277463931762">
<title>IRGENDWAS</title>
</topic>
</topics>
</children>
<summaries>
<summary id="3hudg4310modl8gjmv69em1sk3" range="(0,0)" topic-id="7nmpqo10jakmicd9foi9jpasbs"/>
</summaries>
</topic>
</topics>
</children>
</topic>
<topic id="501jlev4idt2964fdjn802aejc" timestamp="1277457085768">
<title>1.2.2</title>
<children>
<topics type="attached">
<topic id="4npl01bbarppt8kcbmfpqapfgg" timestamp="1277456506196">
<title>Kenntnis der einschlägigen Sicherheitsvorschriften und Schutzmaßnahmen sowie der
sonstigen in Betracht kommenden Vorschriften zum Schutze des Lebens und der Gesundheit</title>
</topic>
</topics>
</children>
</topic>
<topic id="33t5dfmt496n7rbj9m6j89h30t" timestamp="1277457085776">
<title>1.2.3</title>
<children>
<topics type="attached">
<topic id="6upmr323pu42ihtfddg7sehj1p" timestamp="1277456492277">
<title>Die für den Beruf relevanten Maßnahmen und Vorschriften zum Schutz der Umwelt:
Grundkenntnisse über die betrieblichen Maßnahmen zum sinnvollen Energieeinsatz,
Grundkenntnisse über die im Arbeitsbereich anfallenden Reststoffe und über deren Trennung, Verwertung sowie
über die Entsorgung des Abfalls</title>
</topic>
</topics>
</children>
</topic>
<topic id="1oprlfj1qp85cesmm4pht5kcqa" timestamp="1277457085785">
<title>1.2.4</title>
<children>
<topics type="attached">
<topic id="6027gs3181hi3bs1hqruberf22" timestamp="1277456701264">
<title>Grundkenntnisse der aushangpflichtigen arbeitsrechtlichen Vorschriften und
der für den Lehrling wichtigen Behörden, Sozialversicherungsträger und Interessensvertretungen</title>
</topic>
</topics>
</children>
</topic>
<topic id="0l3us2a7fd2165ltthr2a83285" timestamp="1277457085794">
<title>1.2.5</title>
<children>
<topics type="attached">
<topic id="1sbjt2ru8bd481p2696anvls08" timestamp="1277456708737">
<title>Kenntnis über die ergonomische Gestaltung des Arbeitsplatzes</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="7rnsaqiq0cpe9g2gqikle4qapm" timestamp="1277457135240">
<title>1.3 Ausbildung im dualen System</title>
<children>
<topics type="attached">
<topic id="5as551h72otb3mas7ikq2ea4m2" timestamp="1277457133322">
<title>1.3.1</title>
<children>
<topics type="attached">
<topic id="3gvtqp68pjms7uqs0rn6qv02t3" timestamp="1277298890430">
<title>Kenntnis der sich aus dem Lehrvertrag ergebenden Verpflichtungen (§§ 9 und 10 des Berufsausbildungsgesetzes)</title>
<children>
<topics type="attached">
<topic id="0vbraigmt7j4lpckg9c892i4ja" timestamp="1277463761974">
<title>1</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="5ucs0ucl169d8ogp0q6h80kut4" timestamp="1277457133331">
<title>1.3.2</title>
<children>
<topics type="attached">
<topic id="6t9arbstq8q702lq0dm7dg95iu" timestamp="1277298630809">
<title>Kenntnis über Inhalt und Ziel der Ausbildung sowie über wesentliche einschlägige Weiterbildungsmöglichkeiten</title>
</topic>
</topics>
</children>
</topic>
<topic id="3nk81hvkdvmsoh3qheaknadkhn" timestamp="1277457133338">
<title>1.3.3</title>
<children>
<topics type="attached">
<topic id="464huvc57o2q616ia4u70064lq" timestamp="1277298660094">
<title>Kenntnis über Arbeitsorganisation und Arbeitsgestaltung, Teamarbeit und Projektarbeit</title>
</topic>
</topics>
</children>
</topic>
<topic id="0i3llnqh7tscao41fn51m1cpnt" timestamp="1277457166865">
<title>1.3.4</title>
<children>
<topics type="attached">
<topic id="0lr9jtramn678c06douk61pneu" timestamp="1277457172133">
<title>Kenntnis und Anwendung englischer Fachausdrücke</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="5v82k2pj0qpjesnp4fouckdnlg" timestamp="1277457232494">
<title>2. Produkte der Datenverarbeitung</title>
<children>
<topics type="attached">
<topic id="1ou3304eevib8mapqpuolrvd3c" timestamp="1277457255478">
<title>2.1 Einsatzbereiche, technische Entwicklung</title>
<children>
<topics type="attached">
<topic id="6tl8u51dkdueloq19os60ej7qd" timestamp="1277457253457">
<title>2.1.1</title>
<children>
<topics type="attached">
<topic id="5oc28tl1tbv1pij2arhtgong8d" timestamp="1277455410796">
<title>Kenntnis über Hardware und Software, Peripherie, Betriebssysteme und Anwenderprogramme</title>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
</topics>
</children>
</topic>
<topic id="3p0nus0bqlbp1eefpeodfse5pe" timestamp="1277382561143">
<title>Kommunikationstechniker</title>
</topic>
</topics>
</children>
</topic>
<title>Arbeitsblatt 1</title>
</sheet>
</xmap-content>[/XML]

das ist jetzt mein XSL dazu:
[XML]<?xml version="1.0"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:xmind:xmap:xmlns:content:2.0"
exclude-result-prefixes="tns xs">

<xsl:eek:utput
method="xml"
version="1.0"
encoding="iso-8859-1"
indent="yes"/>

<xsl:template match="/">
<xsl:for-each select="tns:xmap-content/tns:sheet/tns:topic/tns:children/tns:topics">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>

<xsl:template match="tns:topics" priority="10">
<excel>
<xsl:for-each select="tns:topic">
<xsl:variable name="beruf" select="tns:title"></xsl:variable>
<xsl:for-each select="tns:children/tns:topics[@type='attached']/tns:topic">
<xsl:variable name="ueberschrift1" select="tns:title"></xsl:variable>
<xsl:for-each select="tns:children/tns:topics[@type='attached']/tns:topic">
<xsl:variable name="ueberschrift2" select="tns:title"></xsl:variable>
<xsl:for-each select="tns:children/tns:topics[@type='attached']/tns:topic">
<xsl:variable name="bbp" select="tns:title"></xsl:variable>
<xsl:for-each select="tns:children/tns:topics[@type='attached']/tns:topic">
<xsl:variable name="fertigkeit" select="tns:title"></xsl:variable>
<xsl:for-each select="tns:children/tns:topics[@type='attached']/tns:topic">
<xsl:variable name="unterrichtseinheit" select="tns:title"></xsl:variable>
<row>
<Beruf><xsl:value-of select="$beruf"/></Beruf>
<ueberschrift1><xsl:value-of select="$ueberschrift1"/></ueberschrift1>
<ueberschrift2><xsl:value-of select="$ueberschrift2"/></ueberschrift2>
<Berufsbildposition><xsl:value-of select="$bbp"/></Berufsbildposition>
<Fertigkeit><xsl:value-of select="$fertigkeit"/></Fertigkeit>
<Unterrichtseinheit><xsl:value-of select="$unterrichtseinheit"/></Unterrichtseinheit>
<Inhalt>
<ul>
<xsl:call-template name="tree"/>
</ul>
</Inhalt>
</row>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</excel>
</xsl:template>

<xsl:template name="tree">
<xsl:for-each select="tns:children/tns:topics/tns:topic">
<li>
<xsl:value-of select="tns:title"/>
<xsl:if test="current()/tns:children/tns:topics/tns:topic">
<ul>
<xsl:call-template name="tree"/>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>[/XML]

so wandle ich in Java um:
Java:
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
		SAXTransformerFactory tf = (SAXTransformerFactory)TransformerFactory.newInstance();
		Transformer t = tf.newTransformer(new StreamSource(xsl));
		t.transform(new DOMSource(d.getDocumentElement()), new StreamResult(System.out));

und das is mein Output:
[XML]<?xml version="1.0" encoding="iso-8859-1"?>Berufsbilder<excel>
<row>
<Beruf>EDV-Techniker</Beruf>
<ueberschrift1>1. Der Lehrbetrieb</ueberschrift1>
<ueberschrift2>1.2 Einrichtungen, Arbeitssicherheit, Unfallverhütung</ueberschrift2>
<Berufsbildposition>1.2.1</Berufsbildposition>
<Fertigkeit>Kenntnis und funktionsgerechte Anwendung der betrieblichen Einrichtungen und der technischen Betriebsmittel und Hilfsmittel</Fertigkeit>
<Unterrichtseinheit>1</Unterrichtseinheit>
<Inhalt>
<ul>
<li>Stempeluhr / Consens</li>
<li>Arbeitszeiterfassung</li>
<li>Urlaubsanträge, Zeitkorrekturen</li>
<li>Verhalten im Brandfall, Rettungsübungen, ...</li>
<li>Krankenstand wo melden</li>
<li>Autopool</li>
<li>interne EDV - Richtlinien</li>
</ul>
</Inhalt>
</row>
<row>
<Beruf>EDV-Techniker</Beruf>
<ueberschrift1>1. Der Lehrbetrieb</ueberschrift1>
<ueberschrift2>1.3 Ausbildung im dualen System</ueberschrift2>
<Berufsbildposition>1.3.1</Berufsbildposition>
<Fertigkeit>Kenntnis der sich aus dem Lehrvertrag ergebenden Verpflichtungen (§§ 9 und 10 des Berufsausbildungsgesetzes)</Fertigkeit>
<Unterrichtseinheit>1</Unterrichtseinheit>
<Inhalt>
<ul/>
</Inhalt>
</row>
</excel>Arbeitsblatt 1[/XML]
das sieht ja ganz gut aus ... bis auf den kleinen aber feinen Fehler dass am Anfang der Titel "Berufsbilder" aufscheint und am Schluss "Arbeitsblatt1" ... wie kann ich denn das noch wegmachen?!
ich versteh gar nicht wieso das überhaupt auftaucht!!!!

mfg, guni
 

Niki

Top Contributor
also bei mir funktioniert die transformation, probier mal diesen code aus:
Java:
	public static void transform(InputStream is, InputStream xsl, Writer out)
			throws TransformerConfigurationException, TransformerException {

		StreamSource xslSource = new StreamSource(xsl);

		String sClass = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
		TransformerFactory factory = null;

		try {
			Class clasz = Class.forName(sClass);
			factory = (TransformerFactory) clasz.newInstance();
		} catch (Exception ex) {
			System.out.println("cannot use factory '" + sClass
					+ "', using standard implementation");
			factory = TransformerFactory.newInstance();
		}

		Transformer transformer = factory.newTransformer(xslSource);
		System.out.println("Transforming using transformer: "
				+ transformer.getClass().getName());

		StreamResult resultOut = new StreamResult(out);

		Source xmlSource = new StreamSource(is);

		transformer.transform(xmlSource, resultOut);
	}
 

Ähnliche Java Themen

Neue Themen


Oben