Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    5

    [XSL] Problema con tag <xsl:template match="">

    Ragazzi ho un problema strano con questo file XSL.

    File XSL
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xslutput method="html" />

    <xsl:template match="corso/modulo/ud">
    <html>
    Prova
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Questo è lXML a cui viene applicato
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE corso SYSTEM "metadati.dtd">

    <corso titolo="[Test] Corso Prova">
    <modulo>
    <titolo>[Test] Modulo Prova</titolo>
    <ud numUF="1">
    <titolo>ioioi</titolo>
    <obiettivi>oip</obiettivi>
    <sommario>poi</sommario>
    <keywords></keywords>
    <autori>Carbone Giuseppe</autori>
    <bibliografia>SuperLibro</bibliografia>
    <sitografia>SuperSito</sitografia>
    <uf id="1">
    <titolo>coccode</titolo>
    <testo Formato="Testo">ciao io sto bene tu come sta?</testo>
    <web_seminar>http://www.pino.it</web_seminar>
    <img>
    <url>img.jpg</url>
    <commento>clicca sul link</commento>
    </img>
    <video>
    <url>video.mpg</url>
    </video>
    <esempio Formato="Img">
    <titolo>titolo di esempio:ciao</titolo>
    <documento>dvinapdivn</documento>
    <html>http://boh?</html>
    <cartella_img />
    </esempio>
    <spiegazione>
    <url>audio.mp3</url>
    </spiegazione>
    <approfondimento Formato="Testo">
    <titolo>Approfondiamo assieme l'argomento</titolo>
    <documento>Per approfondire bisogna documentarsi a fondo su questo argomento</documento>
    <html></html>
    <cartella_img></cartella_img>
    </approfondimento>
    <attività>
    <media Formato="AUDIO">
    <url>video.mp3</url>
    <commento>Bel video. Voto:2/10</commento>
    </media>
    <assegno Formato="Testo">Fare i compiti a casa</assegno>
    </attività>
    </uf>
    </ud>
    </modulo>
    </corso>


    Il risultato della trasformazione xslt dovrebbe essere
    <html>
    Prova
    </html>


    Invece quello che viene fuori è:
    [Test] Modulo Prova
    <html>
    Prova
    </html>
    Cioè mi prende il titolo del modulo e lo visualizza....perchè??
    Qualcuno sa aiutarmi??
    Grazie in anticipo!

  2. #2
    ciao pinuxxp, benvenuto sul forum. :)
    in realtà non è molto chiaro cosa vorresti ottenere con la tua trasformazione: tra parentesi, con Firefox 2.0.0.1 il risultato è quello che vorresti ottenere.
    inoltre, potrebbe essere utile postare il file metadati.dtd che hai associato al documento XML.

    ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    5
    questo è il file metadati.dtd
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!ELEMENT corso (modulo+)>

    <!ATTLIST corso titolo CDATA #REQUIRED>
    <!ELEMENT titolo (#PCDATA)>

    <!ELEMENT modulo (titolo,ud+)>

    <!ATTLIST ud numUF CDATA #REQUIRED>

    <!ELEMENT ud (titolo,obiettivi,sommario,keywords,autori,bibliog rafia,sitografia?,download?,uf*,glossario?,eserciz i?)>
    <!ELEMENT sommario (#PCDATA)>
    <!ELEMENT obiettivi (#PCDATA)>
    <!ELEMENT autori (#PCDATA)>
    <!ELEMENT keywords (#PCDATA)>
    <!ELEMENT bibliografia (#PCDATA)>
    <!ELEMENT sitografia (#PCDATA)>

    <!ELEMENT download (file*)>
    <!ATTLIST file id CDATA #REQUIRED>
    <!ELEMENT file (nome,descrizione)>
    <!ELEMENT nome (#PCDATA)>
    <!ELEMENT descrizione (#PCDATA)>



    <!ATTLIST uf id CDATA #REQUIRED>
    <!ELEMENT uf (titolo,testo,web_seminar, ((img|video)+),((esempio)?),(spiegazione)?,((appro fondimento)?),attività?, richiami?,analitico?, richiami?)>
    <!ELEMENT testo (#PCDATA)>
    <!ATTLIST testo Formato CDATA #REQUIRED>
    <!ELEMENT web_seminar (#PCDATA)>
    <!ELEMENT richiami (richiamo*)>
    <!ATTLIST richiamo id CDATA #REQUIRED>
    <!ELEMENT richiamo (progetto, nUF, visualizza)>
    <!ELEMENT analitico (parola*)>
    <!ATTLIST parola id CDATA #REQUIRED>
    <!ELEMENT parola (#PCDATA)>
    <!ELEMENT progetto (#PCDATA)>
    <!ELEMENT nUF (#PCDATA)>
    <!ELEMENT visualizza (#PCDATA)>

    <!ELEMENT img (url,commento?)>
    <!ELEMENT url (#PCDATA)>
    <!ELEMENT commento (#PCDATA)>

    <!ELEMENT video (url,commento?)>
    <!ELEMENT esempio (titolo,documento,html,cartella_img)>
    <!ELEMENT documento (#PCDATA)>
    <!ELEMENT html (#PCDATA)>
    <!ELEMENT cartella_img (#PCDATA)>
    <!ATTLIST esempio Formato CDATA #REQUIRED>
    <!ELEMENT spiegazione (#PCDATA)>
    <!ELEMENT approfondimento (titolo,documento,html,cartella_img)>
    <!ATTLIST approfondimento Formato CDATA #REQUIRED>
    <!ELEMENT attività (media,assegno)>
    <!ELEMENT assegno (#PCDATA)>
    <!ATTLIST assegno Formato CDATA #REQUIRED>

    <!ELEMENT glossario (voce*)>
    <!ATTLIST voce id CDATA #REQUIRED>
    <!ELEMENT voce (termine,descrizione)>
    <!ELEMENT termine (#PCDATA)>
    <!ELEMENT esercizi (autovalutazione?,esercizi_svolti?,autovalutazione ?)>
    <!ELEMENT autovalutazione (Esercizio)+>
    <!ELEMENT esercizi_svolti (Esercizio)+>
    <!ELEMENT Esercizio (guid?,titolo,aiuto?,testo?,(quesito_VF)*,frase_1? ,frase_2?,frase_3?,frase_4?,corretta?,testo_1?,tes to_associato_1?,testo_2?,testo_associato_2?,testo_ 3?,testo_associato_3?,testo_4?,testo_associato_4?, testo_5?,testo_associato_5?,testo_completo?,tracci a?,soluzione*,quesito?,risposta?,commento_risposta _sbagliata?,risposta_esatta?,risposta_sbagliata_1? ,commento_risposta_sbagliata_1?,risposta_sbagliata _2?,commento_risposta_sbagliata_2?,risposta_sbagli ata_3?,commento_risposta_sbagliata_3?,media?,spieg azione?)>
    <!ATTLIST Esercizio tipo CDATA #IMPLIED>
    <!ATTLIST Esercizio id CDATA #REQUIRED>
    <!ELEMENT guid (#PCDATA)>
    <!ELEMENT aiuto (#PCDATA)>
    <!ELEMENT quesito_VF (#PCDATA)>
    <!ATTLIST quesito_VF id CDATA #REQUIRED>
    <!ATTLIST quesito_VF Formato CDATA #REQUIRED>
    <!ATTLIST quesito_VF esito CDATA #REQUIRED>
    <!ELEMENT frase_1 (#PCDATA)>
    <!ELEMENT frase_2 (#PCDATA)>
    <!ELEMENT frase_3 (#PCDATA)>
    <!ELEMENT frase_4 (#PCDATA)>
    <!ELEMENT corretta (#PCDATA)>
    <!ELEMENT testo_1 (#PCDATA)>
    <!ELEMENT testo_2 (#PCDATA)>
    <!ELEMENT testo_3 (#PCDATA)>
    <!ELEMENT testo_4 (#PCDATA)>
    <!ELEMENT testo_5 (#PCDATA)>
    <!ELEMENT testo_associato_1 (#PCDATA)>
    <!ELEMENT testo_associato_2 (#PCDATA)>
    <!ELEMENT testo_associato_3 (#PCDATA)>
    <!ELEMENT testo_associato_4 (#PCDATA)>
    <!ELEMENT testo_associato_5 (#PCDATA)>
    <!ELEMENT testo_completo (#PCDATA)>
    <!ELEMENT risposta (#PCDATA)>
    <!ATTLIST risposta Formato CDATA #REQUIRED>
    <!ELEMENT media (url,commento?)>
    <!ATTLIST media Formato CDATA #REQUIRED>
    <!ATTLIST risposta esito CDATA #REQUIRED>
    <!ELEMENT risposta_esatta (#PCDATA)>
    <!ATTLIST risposta_esatta Formato CDATA #REQUIRED>
    <!ELEMENT risposta_sbagliata_1 (#PCDATA)>
    <!ATTLIST risposta_sbagliata_1 Formato CDATA #REQUIRED>
    <!ELEMENT risposta_sbagliata_2 (#PCDATA)>
    <!ATTLIST risposta_sbagliata_2 Formato CDATA #REQUIRED>
    <!ELEMENT risposta_sbagliata_3 (#PCDATA)>
    <!ATTLIST risposta_sbagliata_3 Formato CDATA #REQUIRED>
    <!ELEMENT commento_risposta_sbagliata (#PCDATA)>
    <!ELEMENT commento_risposta_sbagliata_1 (#PCDATA)>
    <!ELEMENT commento_risposta_sbagliata_2 (#PCDATA)>
    <!ELEMENT commento_risposta_sbagliata_3 (#PCDATA)>
    <!ELEMENT quesito (#PCDATA)>
    <!ATTLIST quesito Formato CDATA #REQUIRED>
    <!ELEMENT traccia (#PCDATA)>
    <!ATTLIST traccia Formato CDATA #REQUIRED>
    <!ELEMENT soluzione (#PCDATA)>
    <!ATTLIST soluzione Formato CDATA #REQUIRED>
    <!ATTLIST soluzione id CDATA #REQUIRED>

    In realtà per effettuare la trasformazione utilizzo Java, ed in particolare il package javax.xml.transform.*;
    Questo è il codice che mi permette la trasformazione:

    public static void trasforma(String fileXML, String fileXSL){

    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    //factory.setNamespaceAware(true);
    //factory.setValidating(true);

    try {
    File stylesheet = new File(fileXSL);
    File datafile = new File(fileXML);

    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(datafile);

    // Use a Transformer for output
    TransformerFactory tFactory =
    TransformerFactory.newInstance();
    StreamSource stylesource = new StreamSource(stylesheet);
    Transformer transformer = tFactory.newTransformer(stylesource);

    DOMSource source = new DOMSource(document);
    StreamResult result = new StreamResult(System.out);
    transformer.transform(source, result);

    } catch .....{
    ......
    }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.