2014-04-25 2 views
1

Docbook-XSL을 사용하여 XML 파일을 처리하고 HTML 및 XML 출력 파일을 생성합니다. 이 파일은 Eclipse RCP 응용 프로그램의 온라인 도움말에 사용됩니다.XSLT가 이름 형식 ( ) 대신 숫자 형식 ( )으로 문자를 이스케이프하도록하려면?

표준 XSL은 F1 컨텍스트 도움말을 활성화하는 데 필요한 contexts.xml 파일을 생성하지 않으므로 여기에서 온라인으로 찾은 XSL을 사용했습니다 http://blogs.itemis.de/leipzig/archives/691.

독일어 움라우트를 원본 텍스트에 추가 할 때까지 제대로 작동합니다. 이러한 문자는 & auml과 같은 명명 된 엔티티로 변환됩니다. 및 & szlig; 이러한 엔터티를 찾을 수 없으므로 출력 된 XML에 오류가 발생합니다.

& # 223;과 같이 번호가 매겨진 엔티티를 사용하도록 XSL 프로세서에 지시하는 방법이 있습니까? 당신이 다음 색슨를 사용하는 경우

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook" 
     xmlns:exsl="http://exslt.org/common" version="1.0" 
     exclude-result-prefixes="exsl db ng"> 

     <!-- make sure the path to the standard eclipse.xsl is correct --> 
     <xsl:import href="docbook-xsl-1.78.1/eclipse/eclipse3.xsl" /> 


     <xsl:param name="manifest"> 
      1 
     </xsl:param> 
     <xsl:param name="create.plugin.xml"> 
      1 
     </xsl:param> 
     <xsl:param name="create.context.xml"> 
      1 
     </xsl:param> 
     <xsl:param name="context.constants.package"> 
      org.example.help 
     </xsl:param> 

     <xsl:template name="plugin.xml"> 
      <xsl:if test="$create.context.xml = '1'"> 
       <xsl:call-template name="context.xml" /> 
       <xsl:call-template name="contextconstants"> 
        <xsl:with-param name="package"> 
         <xsl:value-of select="$context.constants.package" /> 
        </xsl:with-param> 
       </xsl:call-template> 
      </xsl:if> 

      <xsl:if test="$create.plugin.xml = '1'"> 
       <xsl:call-template name="write.chunk"> 
        <xsl:with-param name="filename"> 
         <xsl:if test="$manifest.in.base.dir != 0"> 
          <xsl:value-of select="$base.dir" /> 
         </xsl:if> 
         <xsl:value-of select="'plugin.xml'" /> 
        </xsl:with-param> 
        <xsl:with-param name="method" select="'xml'" /> 
        <xsl:with-param name="encoding" select="'utf-8'" /> 
        <xsl:with-param name="indent" select="'yes'" /> 
        <xsl:with-param name="content"> 
         <xsl:choose> 
          <xsl:when test="$manifest = '1'"> 
           <plugin> 
            <extension point="org.eclipse.help.toc"> 
             <toc file="toc.xml" primary="true" /> 
            </extension> 
            <extension point="org.eclipse.help.contexts"> 
             <contexts file="contexts.xml"></contexts> 
            </extension> 
           </plugin> 
          </xsl:when> 
          <xsl:otherwise> 
           <plugin name="{$eclipse.plugin.name}" id="{$eclipse.plugin.id}" 
            version="1.0" provider-name="{$eclipse.plugin.provider}"> 
            <extension point="org.eclipse.help.toc"> 
             <toc file="toc.xml" primary="true" /> 
            </extension> 
           </plugin> 
          </xsl:otherwise> 
         </xsl:choose> 
        </xsl:with-param> 
       </xsl:call-template> 
      </xsl:if> 
     </xsl:template> 


     <xsl:template name="context.xml"> 
      <xsl:call-template name="write.chunk"> 
       <xsl:with-param name="filename" select="'contexts.xml'" /> 
       <xsl:with-param name="method" select="'xml'" /> 
       <xsl:with-param name="encoding" select="'utf-8'" /> 
       <xsl:with-param name="indent" select="'yes'" /> 
       <xsl:with-param name="quiet" select="$chunk.quietly" /> 
       <xsl:with-param name="content"> 
        <contexts> 
         <xsl:apply-templates select="/*" mode="context.xml" /> 
        </contexts> 
       </xsl:with-param> 
      </xsl:call-template> 
     </xsl:template> 


     <xsl:template 
      match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" 
      mode="context.xml"> 
      <xsl:variable name="title"> 
       <xsl:if test="$eclipse.autolabel=1"> 
        <xsl:variable name="label.markup"> 
         <xsl:apply-templates select="." mode="label.markup" /> 
        </xsl:variable> 
        <xsl:if test="normalize-space($label.markup)"> 
         <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" /> 
        </xsl:if> 
       </xsl:if> 
       <xsl:apply-templates select="." mode="title.markup" /> 
      </xsl:variable> 

      <xsl:variable name="href"> 
       <xsl:call-template name="href.target.with.base.dir"> 
        <xsl:with-param name="context" select="/" /> 
       </xsl:call-template> 
      </xsl:variable> 

      <!-- <xsl:message>Node=<xsl:value-of select="name(.)"></xsl:value-of>, 
       ID=<xsl:call-template name="object.id"> <xsl:with-param name="object" select="."/> 
       </xsl:call-template></xsl:message> --> 

      <xsl:call-template name="acontext"> 
       <xsl:with-param name="id"> 
        <xsl:call-template name="object.id"> 
         <xsl:with-param name="object" select="." /> 
        </xsl:call-template> 
       </xsl:with-param> 
       <xsl:with-param name="label" select="$title" /> 
       <xsl:with-param name="href" select="$href" /> 
      </xsl:call-template> 
      <xsl:apply-templates 
       select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" 
       mode="context.xml" /> 
     </xsl:template> 

     <xsl:template name="acontext"> 
      <xsl:param name="id" /> 
      <xsl:param name="label" /> 
      <xsl:param name="href" /> 
      <xsl:message><xsl:value-of select="$id"/>, <xsl:value-of select="$href"/> 
      </xsl:message> 
      <context id="{normalize-space($id)}" title=""> 
       <description /> 
       <topic href="{$href}" label="{normalize-space($label)}" /> 
      </context> 
     </xsl:template> 


     <xsl:template name="contextconstants"> 
      <xsl:param name="package" /> 
      <xsl:call-template name="write.chunk"> 
       <xsl:with-param name="filename" select="'ContextConstants.java'" /> 
       <xsl:with-param name="method" select="'java'" /> 
       <xsl:with-param name="encoding" select="'utf-8'" /> 
       <xsl:with-param name="indent" select="'yes'" /> 
       <xsl:with-param name="quiet" select="$chunk.quietly" /> 
       <xsl:with-param name="content"> 
        package 
        <xsl:value-of select="$package" /> 
        ; 
        public class ContextConstants{ 
        <xsl:apply-templates select="/*" mode="contextconstants" /> 
        } 
       </xsl:with-param> 
      </xsl:call-template> 
     </xsl:template> 

     <xsl:template 
      match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" 
      mode="contextconstants"> 
      <xsl:variable name="title"> 
       <xsl:if test="$eclipse.autolabel=1"> 
        <xsl:variable name="label.markup"> 
         <xsl:apply-templates select="." mode="label.markup" /> 
        </xsl:variable> 
        <xsl:if test="normalize-space($label.markup)"> 
         <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" /> 
        </xsl:if> 
       </xsl:if> 
       <xsl:apply-templates select="." mode="title.markup" /> 
      </xsl:variable> 

      <xsl:variable name="href"> 
       <xsl:call-template name="href.target.with.base.dir"> 
        <xsl:with-param name="context" select="/" /> 
       </xsl:call-template> 
      </xsl:variable> 

      <xsl:call-template name="acontextconstant"> 
       <xsl:with-param name="id"> 
        <xsl:call-template name="object.id"> 
         <xsl:with-param name="object" select="." /> 
        </xsl:call-template> 
       </xsl:with-param> 
       <xsl:with-param name="label" select="$title" /> 
       <xsl:with-param name="href" select="$href" /> 
      </xsl:call-template> 
      <xsl:apply-templates 
       select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index" 
       mode="contextconstants" /> 
     </xsl:template> 

     <xsl:template name="acontextconstant"> 
      <xsl:param name="id" /> 
      <xsl:param name="label" /> 
      <xsl:param name="href" /> 
      public static final String C_ 
      <xsl:value-of select="translate($id,'-','_')" /> 
      =" 
      <xsl:value-of select="$id" /> 
      "; 
     </xsl:template> 
    </xsl:stylesheet> 
+0

"온라인에서 찾은 XSL"- 링크를 제공하고이 스타일 시트의 관련 부분을 포함하도록 질문을 편집 할 수 있습니까? 코드가 어떻게 생겼는지 모를 경우 코드를 디버깅 할 수 없습니다. –

+0

XSLT가 XML 출력이 아닌 HTML을 생성하도록 구성된 것처럼 들리는데, ''선언을 표시 할 수 있습니까? –

+0

@IanRoberts - 완료. XSL은 DOCBOOK XSL 위에 추가됩니다. 이 표준은 MANIFEST.MF 및 toc.xml과 같은 많은 HTML 파일을 생성합니다. 이 XSL은 contexts.xml도 만듭니다. – paul

답변

0

:

최상위 XSL을 (나는 ... 검색을 수행하고 출력 파일을 대체하지만이 조금 서투른 것 같다 수) 당신은 색슨 시도해 볼 수도 있습니다 : 문자 표현 :

http://www.saxonica.com/documentation/#!extensions/output-extras/character-representation

를 참조 색슨-PE 이상이 필요합니다.

그러나 귀하의 요구 사항에 대해 혼란 스럽습니다. XML 출력을 원하면 method = "xml"을 사용하십시오. 이 경우 태그가 생성되지 않습니다. 태그를 원하지만 HTML 문자 참조를 원하지 않는다면 어떤 종류의 하이브리드가 필요할 것입니다. 왜 그런지 모르겠습니다. 아마도 method = "xhtml"이 당신의 필요에 맞을까요?