2013-02-25 1 views
0

나는 아래 XML 문서를 가지고있다. 여기에 xslt 문서를 만들어서 '.'앞에있는 번호 만 선택하려고합니다. 그것을 추가하여 'BVI-Chapter01'과 같은 문자열을 만들고이 문자열에만 앵커 태그를 지정하면 여기에서 01은 '.'앞의 숫자를 변경합니다. 아래의 XML 문서를 참조하십시오.xslt에서 숫자와 concatinate 만 선택

<index> 
<title>INDEX</title> 
<indexdiv> 
    <title>A</title> 
    <indexentry> 
     <primaryie> 
      <content-style font-style="bold">Administration</content-style> 
     </primaryie> 
     <secondaryie>administration order 7.251, 7.254</secondaryie> 
     <tertiaryie level="1">application for 7.255-7.257</tertiaryie> 
     <tertiaryie level="2">conditions to be satisfied 7.258-7.260</tertiaryie> 
     <tertiaryie level="1">blocking</tertiaryie> 
     <tertiaryie level="2">qualifying administrative receiver 7.261-7.263</tertiaryie> 
     <tertiaryie level="1">discharge of 7.288-7.280</tertiaryie> 
     <tertiaryie level="1">effect of 7.264</tertiaryie> 
     <tertiaryie level="2">directors not terminated 7.265, 7.266</tertiaryie> 
     <tertiaryie level="1">moratorium 7.267</tertiaryie> 
     <tertiaryie level="2">administrative receiver, appointment 7.270</tertiaryie> 
     <tertiaryie level="2">commencement 7.268</tertiaryie> 
     <tertiaryie level="2">disposal of changed assets 7.269</tertiaryie> 
     <tertiaryie level="2">judicial decisions 7.273</tertiaryie> 
     <secondaryie>administrator 7.274, <content-style font-style="italic">see also </content-style> 
      <content-style font-style="bold">Administrators</content-style> 
     </secondaryie> 
     <secondaryie>British Virgin Island companies 7.250</secondaryie> 
     <secondaryie>creditors, role of 7.283</secondaryie> 
     <tertiaryie level="1">application to court for directions 7.286</tertiaryie> 
     </indexentry> 
     </indexdiv> 
     </index> 

다음과 같이 출력하고 싶습니다.

<div class="index"> 
      <a name="BVI_IDX_01"> </a> 
      <div class="index-title">INDEX</div> 
      <div class="indexdiv"> 
       <div class="indexentry"> 
        <div class="primaryie"> 
         <span class="font-style-bold">Administration</span> 
        </div> 
        <div class="secondaryie">administration order <a href="er:#BVI_CH_07">7.251</a>, <a href="er:#BVI_CH_07">7.254</a> 
        </div> 
        <div class="tertiaryie-1">application for <a href="er:#BVI_CH_07">7.255</a>&#x2013;<a href="er:#BVI_CH_07">7.257</a> 
        </div> 
        <div class="tertiaryie-2">conditions to be satisfied <a href="er:#BVI_CH_07/P7-258">7.258</a>&#x2013;<a href="er:#BVI_CH_07/P7-260">7.260</a> 
        </div> 
        <div class="tertiaryie-1">blocking</div> 
        <div class="tertiaryie-2">qualifying administrative receiver <a href="er:#BVI_CH_07/P7-261">7.261</a>&#x2013;<a href="er:#BVI_CH_07/P7-263">7.263</a> 
        </div> 
        <div class="tertiaryie-1">discharge of <a href="er:#BVI_CH_07">7.288</a>&#x2013;<a href="er:#BVI_CH_07">7.280</a> 
        </div> 
        <div class="tertiaryie-1">effect of <a href="er:#BVI_CH_07">7.264</a> 
        </div> 
        <div class="tertiaryie-2">directors not terminated <a href="er:#BVI_CH_07">7.265</a>, <a href="er:#BVI_CH_07">7.266</a> 
        </div> 
        <div class="tertiaryie-1">moratorium <a href="er:#BVI_CH_07">7.267</a> 
        </div> 
        <div class="tertiaryie-2">administrative receiver, appointment <a href="er:#BVI_CH_07">7.270</a> 
        </div> 
        <div class="tertiaryie-2">commencement <a href="er:#BVI_CH_07>7.268</a> 
        </div> 
        <div class="tertiaryie-2">disposal of changed assets <a href="er:#BVI_CH_07">7.269</a> 
        </div> 
        <div class="tertiaryie-2">judicial decisions <a href="er:#BVI_CH_07">7.273</a> 
        </div> 
        <div class="secondaryie">administrator <a href="er:#BVI_CH_07">7.274</a>, <span class="font-style-italic">see also</span> 
         <span class="font-style-bold">Administrators</span> 
        </div> 
        <div class="secondaryie">British Virgin Island companies <a href="er:#BVI_CH_07">7.250</a> 
        </div> 
        <div class="secondaryie">creditors, role of <a href="er:#BVI_CH_07">7.283</a> 
        </div> 
        <div class="tertiaryie-1">application to court for directions <a href="er:#BVI_CH_07">7.286</a> 
        </div> 
        <div class="tertiaryie-1">proposals, amendment <a href="er:#BVI_CH_07">7.284</a>, <a href="er:#BVI_CH_07">7.285</a> 
        </div> 
        <div class="tertiaryie-1">unfair prejudice <a href="er:#BVI_CH_07">7.287</a>, <a href="er:#BVI_CH_07">7.289</a> 

감사

+1

난 당신이 솔직해야 물어,하지만 당신은 당신의 예상 출력을 표시하는 질문을 편집 할 수 있습니다, 또한 어떤 XSLT 현재 시도 것을 생각한다. 감사! –

+0

안녕하세요, 스크린 샷을 게시 할 수 없어서 소스 출력을 업데이트했습니다. 여기에 내 소스 출력의 일부일뿐입니다. 여기에 출력에 700 줄의 소스 코드가 있습니다. 'er : # BVI_CH_07'xml의 숫자에 따라 숫자가 변경됩니다. 'administration order 7.251 '이고 xml에'administration order 1.251 '이 있으면'er : # BVI_CH_01 '이되어야합니다. 응답에 다시 한 번 감사드립니다. –

+0

사실, 이것은 그리 간단하지 않습니다! XSLT 2.0을 사용할 수 있습니까? –

답변

0

분석 문자열 2.0가 사용하는 텍스트 노드에서 필요한 패턴을 검색하는 XSLT의 다음 솔루션입니다.

내가 링크

<a href="er:#BVI_CH_07/P7-261">7.261</a> 

이런 종류의 대신 링크

또한
<a href="er:#BVI_CH_07">7.261</a> 

의 이러한 종류의 인쇄 할 때의 논리를 찾을 수 없기 때문에 이러한 변화는 정확히 당신이 원하는 것을 수행하지 않는다 그러나 나는 참조는 2 차 요소와 3 차 요소에만 존재할 수 있다고 가정하고있다.


XSLT 2.0

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="html" indent="yes" /> 

    <!-- Use this string to replace all numbers on the text by a 
     a different character which cannot be present in the text (#)--> 
    <xsl:variable name="str-numbers" select="''" /> 
    <xsl:variable name="str-special-char" select="'#'" /> 
    <xsl:variable name="str-special-seq" select="'##########'" /> 

    <!-- Build the index header structure --> 
    <xsl:template match="index"> 
     <div class="index"> 
      <a name="BVI_IDX_01" /> 
      <div class="index-title"><xsl:value-of select="title" /></div> 
      <div class="indexdiv"> 
       <xsl:apply-templates select="indexdiv" /> 
      </div> 
     </div> 
    </xsl:template> 

    <!-- Ignore title from index div element --> 
    <xsl:template match="indexdiv/title" /> 

    <!-- Transform main elements to divs --> 
    <xsl:template match="indexentry|primaryie|secondaryie|indexdiv|indexentry"> 
     <div class="{local-name()}"> 
      <xsl:apply-templates select="node()" /> 
     </div> 
    </xsl:template> 

    <xsl:template match="tertiaryie"> 
     <div class="{concat(local-name(), '-', @level)}"> 
      <xsl:apply-templates select="node()" /> 
     </div> 
    </xsl:template> 

    <xsl:template match="content-style"> 
     <span> 
      <xsl:attribute name="class"> 
       <xsl:value-of select="concat(local-name(@*[1]), '-', @*[1])" /> 
       <xsl:for-each select="@*[position() > 1]"> 
        <xsl:value-of select="concat(' ', local-name(), '-', .)" /> 
       </xsl:for-each> 
      </xsl:attribute> 
      <xsl:apply-templates select="node()" /> 
     </span> 
    </xsl:template> 

    <!-- Transform numbers from textnodes within tertiaryie 
     and secondaryie elements --> 
    <xsl:template match="secondaryie/text()|tertiaryie/text()"> 
     <!-- Use a regular expression to match the desired pattern 
      within the text --> 
     <xsl:analyze-string select="." regex="((\d+)\.\d+)"> 
      <!-- A reference is found, print hyperlink --> 
      <xsl:matching-substring> 
       <a href="{concat('er:#BVI_CH_', format-number(number(regex-group(2)), '00'))}"> 
        <xsl:value-of select="regex-group(1)" /> 
       </a> 
      </xsl:matching-substring> 
      <!-- Output the text which do not match the given pattern --> 
      <xsl:non-matching-substring> 
       <xsl:value-of select="." /> 
      </xsl:non-matching-substring> 
     </xsl:analyze-string> 
    </xsl:template> 


</xsl:stylesheet>