XML 설정 :하는 방법을 다시 숫자 필터링 요소
<?xml version="1.0" encoding="utf-8"?>
<book>
<chapter>
<section name="a">...</section>
<section name="b">...</section>
<section name="c">...</section>
<section name="d">...</section>
<section name="e">...</section>
...
</chapter>
<appendix>
<section name="reference">...</section>
</appendix>
</book>
안녕하세요, 저는 chapter
및 appendix
노드에서 출력 모든 sections
로합니다. 부록 아래에있는 섹션이 정확하게 인쇄됩니다. 그러나 장 아래의 모든 섹션이을 인쇄 할 수있는 것은 아니며 일부 외부 조건 (섹션 이름이 Java 응용 프로그램에서 전달 된 허용 목록에있는 경우)에 따라 다릅니다.
원하는 결과
- B .. : 또한
chapter
아래sections
은 다음과 같은 섹션 이름 전에 올바른 시퀀스 번호를 출력한다 .
(섹션 a, c, e가 필터링됨을 의미 함)
제 질문은 //chapter/section
에 대해 위의 원하는 출력을 어떻게 생성 할 수 있습니까? 어떤 힌트 또는 도움이 높은
내 XSL :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://example.com/namespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="validChapters" />
<xsl:function name="ex:isValidChapter" as="xs:boolean">
<xsl:param name="str-in" as="xs:string"/>
<xsl:choose>
<xsl:when test="contains($validChapters, $str-in)">
<xsl:sequence select="true()" />
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="false()" />
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="/">
<xsl:apply-templates select="chapter" />
<xsl:apply-templates select="appendix" />
</xsl:template>
<xsl:template match="chapter">
...
<xsl:apply-templates select="section" />
</xsl:template>
<xsl:template match="appendix">
...
<xsl:apply-templates select="section" />
</xsl:template>
<xsl:template match="section">
...
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//chapter/section">
<xsl:if test="ex:isValidChapter(@name)">
<fo:block>
<xsl:number format="1."/>
<xsl:value-of select="@name" />
</fo:block>
<xsl:apply-templates />
</xsl:if>
</xsl:template>
...
</xsl:stylesheet>
샘플 XML 데이터 및 원하는 출력을 통해보다 명확하게 설명하십시오. –
"허용 목록"은 어디에 저장되어 있습니까? –
허용 목록은 java 응용 프로그램에서 전달되며 쉼표로 구분 된 문자열 형식이므로 contains 함수를 사용합니다. –