2016-04-14 10 views
1

Ich erzeuge ein PDF mit FOP. Das PDF enthält einen Fragebogenabschnitt, der ein einfaches HTML (d. H. <p> <strong> <em>) zwischen den XML-Tags enthält. Meine Lösung bestand darin, Vorlagen auf diese Tags in der XSL-Datei anzuwenden, die alles zwischen den Tags <p> und so weiter stylen würden. Ich habe jetzt eine grundlegende Vorlage eingerichtet, und ich glaube, dass ich Probleme mit wie die XSL-Datei die <p> Tags innerhalb der XML findet. Ich denke, da sich die HTML-Tags in einem anderen Tag befinden, funktioniert mein XSL nicht wie erwartet. Ich frage mich: Wie würden Sie diese inneren HTML-Tags mit XSL-Vorlagen gestalten?Html in einer fop/xsl Datei

Das XML wird wie folgt generiert. Sie können die HTML-Tags innerhalb der <QuestionText> Tags sehen.

<xml> 
    <Report> 
     <Stuff> 
      <BasicInfo> 
       <InfoItem> 
        <InfoName>ID</InfoName> 
        <InfoData>555</InfoData> 
       </InfoItem> 
       <InfoItem> 
        <InfoName>Name</InfoName> 
        <InfoData>Testing</InfoData> 
       </InfoItem> 
      </BasicInfo> 

      <SubReports title="Employee Reports"> 
       <SubReport> 
        <Question> 
         <QuestionText> 
          <p>1. Are the pads secure?</p> 
         </QuestionText> 
         <AnswerText>Yes</AnswerText> 
        </Question> 
        <Question> 
         <QuestionText> 
          <p> 
           2. <strong>Are the pads in good shape?</strong>&nbsp; 
          </p> 
         </QuestionText> 
         <AnswerText>Yes</AnswerText> 
        </Question> 
       </SubReport> 
      </SubReports> 
     </Stuff> 
    </Report> 
</xml> 

Dann habe ich eine XSL-Vorlage, um die XML-

<xsl:template match="Stuff"> 
    <fo:block> 
    <fo:block font-size="32pt" text-align="center" font-weight="bold">Report</fo:block> 
    </fo:block> 
<xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="SubReports"> 
    <xsl:for-each select="SubReport"> 
    <xsl:for-each select="Question"> 
     <fo:block xsl:use-attribute-sets="question"><xsl:apply-templates /></fo:block> 
     <fo:block xsl:use-attribute-sets="answer"><xsl:value-of select="AnswerText" /></fo:block> 
    </xsl:for-each> 
    </xsl:for-each> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText"> 
    <fo:block><xsl:apply-templates /></fo:block> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText/p"> 
    <fo:block padding-before="10pt"><xsl:apply-templates /></fo:block> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText/strong"> 
    <fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText/em"> 
    <fo:inline font-style="italic"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

Sind die Spiel-Tags für die xsl:templates Hinweis auf die richtige Position auf den HTML-Tags stylen? Wenn nicht, wo soll ich sie zeigen? Vielen Dank!

Antwort

3

Im Moment haben Sie Ihre Vorlage Streichhölzer den vollständigen Pfad zu dem Elemente im Spiel Attribute

<xsl:template match="SubReports/SubReport/Question/QuestionText/strong"> 

Aber das wird das strong Element in dem Fall nicht übereinstimmen, wo sie ein Kind des p Elements ist. Jetzt können Sie das tun ...

<xsl:template match="SubReports/SubReport/Question/QuestionText/p/strong"> 

Aber Sie müssen tatsächlich nicht den vollständigen Pfad hier angeben. Es sei denn, Sie wollten ein ganz bestimmtes Element finden. Diese Vorlagenübereinstimmung würde auch den Trick machen.

<xsl:template match="strong"> 

So können Sie Ihre aktuelle Vorlagen mit diesen statt

<xsl:template match="p"> 
    <fo:block padding-before="10pt"><xsl:apply-templates /></fo:block> 
</xsl:template> 

<xsl:template match="strong"> 
    <fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

<xsl:template match="em"> 
    <fo:inline font-style="italic"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

Sie ersetzen auch xsl:apply-templates so diese Arbeit im Falle von mehreren verschachtelten HTML-Tags. Zum Beispiel <p><strong><em>Test</em></strong></p>

Verwandte Themen