Announcement

Collapse
No announcement yet.

PHP-Silbentrennung mit XSL aufrufen

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

  • PHP-Silbentrennung mit XSL aufrufen

    Hallo Forum,

    ich versuche gerade eine PHP-Silbentrennung in mein XSL einzubetten. Die Quelle ist http://phphyphenator.yellowgreen.de/. Das klappt soweit ganz gut, d.h. * wird richtig eingefügt - nur leider wird es auch mitausgegeben.

    Also z.B.: Sil*ben*trenn*ung

    Im Quelltext steht das * in dieser Form: ­

    Hier lade ich den XSLT-Prozess:

    Code:
    header('content-type: text/html; charset=utf-8');
    $GLOBALS["language"] = "de";
    $GLOBALS["path_to_patterns"] = "./patterns/";
    $GLOBALS["dictionary"] = "dictionary.txt";
    $GLOBALS["hyphen"] = "*";
    $GLOBALS["leftmin"] = 2;
    $GLOBALS["rightmin"] = 2;
    $GLOBALS["charmin"] = 2;
    $GLOBALS["charmax"] = 10;
    $GLOBALS["exclude_tags"] = array("code", "pre", "script", "style");
    
    include("./hyphenation.php");
    
    function hyphen($text)
    {
    	$content = hyphenation($text);
    	//return str_replace('/^­/', '*', $text);
    	return $content;
    }
    
    $sXslFile = './xslt/idml2html_bound.xsl';
    
    //Wahl des Spreadfiles
    $sXmlFile = './publish/' . $docname . '/Spreads/Spread_' . $idNumber . '.xml';
    
    //XSLT Process
    $xml_Doc = new DOMDocument();
    $xml_Doc->load($sXmlFile);
    
    $xslt = new XSLTProcessor;
    $xslt->registerPHPFunctions();
    $xslt->importStyleSheet(DomDocument::load($sXslFile));
    
    //Ausgabe des HTML-Codes
    $output = $xslt->transformToXML($xml_Doc);
    echo $output;
    Das ist der entsprechende Quellcode, meines XSL (Namespace für php:function ist eingebettet):

    Code:
    [...]
    <xsl:for-each select="*">
    	<xsl:if test="ancestor-or-self::Content">
    		<xsl:value-of select="php:function('hyphen', string())"/>
    	</xsl:if>
    	<xsl:if test="ancestor-or-self::Br">
    		<br />
    	</xsl:if>
    </xsl:for-each>
    [...]
    Ich danke Euch für Eure Hilfe.

    Gruss
    Dom

  • #2
    Wie sieht denn ein Beispiel XML-Eingabeelement aus, was für eine HTML-Ausgabe willst du dann dafür erzeugen?
    Was macht denn der reine PHP-Code anders als der Aufruf aus XSLT?

    Comment


    • #3
      Hallo,

      danke für die Antwort. Ich muss noch erwähnen, dass sämtliche * in o.g. Code die gültige Schreibweise von $shy; darstellen sollten, der Browser wandelt das natürlich um. Hier ein Beispiel XML:

      Code:
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="7.5">
      	<Story Self="u12b" AppliedTOCStyle="n" TrackChanges="false" StoryTitle="$ID/" AppliedNamedGrid="n">
      		<StoryPreference OpticalMarginAlignment="false" OpticalMarginSize="12" FrameType="TextFrameType" StoryOrientation="Horizontal" StoryDirection="LeftToRightDirection"/>
      		<InCopyExportOption IncludeGraphicProxies="true" IncludeAllResources="false"/>
      		<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Fliesstext">
      			<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">
      				<Content>Zunächst aber ein kleines Vorwort zu diesem Projekt. [...] biete dazu aber auch neue Funktionen an.</Content>
      			</CharacterStyleRange>
      		</ParagraphStyleRange>
      	</Story>
      </idPkg:Story>
      Der vollständige XSL Abschnitt ist:

      Code:
      <!--Absatzstil-->
                                          <xsl:for-each select="document($parentStory)//ParagraphStyleRange">
                                              <p>
                                                  <xsl:attribute name="class">
                                                      <xsl:value-of select="substring(@AppliedParagraphStyle,16)"/>
                                                  </xsl:attribute>
                                                  <!--Zeichenstil-->
                                                  <xsl:for-each select="CharacterStyleRange">
                                                      <span>
                                                          <xsl:attribute name="class">
                                                              <xsl:value-of select="substring(@AppliedCharacterStyle,16)"/>
                                                          </xsl:attribute>
                                                          <!--Inhalt-->
                                                         	<xsl:for-each select="*">
                                                         	    <xsl:if test="ancestor-or-self::Content">
      //<xsl:value-of select="." /> gibt alles ohne Silbentrennung aus                                                   	        
      <xsl:value-of select="php:function('hyphen', string())"/>
                                                         	    </xsl:if>
                                                         	    <xsl:if test="ancestor-or-self::Br">
                                                         	        <br />
                                                         	    </xsl:if>
                                                          </xsl:for-each>
                                                      </span>
                                                  </xsl:for-each>
                                              </p>
                                          </xsl:for-each>
      Danke und Gruss
      Dom

      Comment


      • #4
        Hier mal ein Screenshot

        Wie gesagt im Quellcode steht dann "&amp;shy;" wo "$shy;" mit einem & anstatt $ stehen sollte.
        Attached Files

        Comment


        • #5
          Ich glaube, du suchst
          Code:
          <xsl:value-of disable-output-escaping="yes" select="php:function('hyphen', string())"/>

          Comment


          • #6
            Wow

            Ich bin begeistert, dass klappt tadellos. Vielen vielen Dank. Ich liebe dieses Forum.

            Gruss und ein schönes WE
            Dom

            Comment

            Working...
            X