0
내가 여러 주제를 데
를 사용하여 요소 태그를 재정렬 할 필요가, 내가 ID의내가 XSLT
내 입력 XML을 번호와 주제 요소와 함께 섹션 태그를 포함해야하는 것은 :
<Article>
<Title>Mam</Title>
<Items>
<Item>
<Name>cyst1?</Name>
<Body>
<h1>aaa</h1><p>knee1.</p>
<h2>bbb</h2><p>knee2.</p>
</Body>
</Item>
<Item>
<Name>cyst2?</Name>
<Body>
<p>knee3.</p>
</Body>
</Item>
</Items>
XSL 내가 사용 등 :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all">
<xsl:template match="Article">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Title"/>
<xsl:template match="h1"/>
<xsl:template match="h2"/>
<xsl:template match="Items">
<xsl:for-each-group select="*" group-starting-with="Items">
<topic>
<xsl:attribute name="id">topic_Head<xsl:number count="Items | Item"/>
</xsl:attribute>
<title>
<xsl:value-of select="//Title"/>
</title>
<xsl:for-each-group select="current-group()" group-starting-with="Item">
<xsl:choose>
<xsl:when test="self::Item">
<topic>
<xsl:attribute name="id">topic_<xsl:number count="Items | Item"/>
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</topic>
</xsl:when>
<xsl:otherwise>
<body>
<xsl:apply-templates select="current-group()"/>
</body>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</topic>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="Body">
<body>
<xsl:apply-templates/>
</body>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="Name">
<title>
<xsl:apply-templates/>
</title>
</xsl:template>
출력은 내가했기 때문에 :
<topic id="topic_1">
<title>Mam</title>
<topic id="topic_2">
<title>cyst1?</title>
<body>
<p>knee1.</p><p>knee2.</p>
</body>
</topic>
<topic id="topic_3">
<title>cyst2?</title>
<body>
<p>knee3.</p>
</body>
</topic>
예상 출력 : 나는 Id 특성과 부와 당 가까이 오는 H1 및 H2 필요
<topic id="topic_1">
<title>Mam</title>
<topic id="topic_2">
<title>cyst1?</title>
<body>
<section id="section1">
<title>aaa</title><p>knee1.</p>
<section id="section2">
<title>bbb</title><p>knee2.</p>
</section>
</section>
</body>
</topic>
<topic id="topic_3">
<title>cyst2?</title>
<body>
<p>knee3.</p>
</body>
</topic>
헤더 순서.
코딩 해주세요. 미리 감사드립니다.
XML 및 XSLT 코드를 올바르게 들여 씁니다. – Tomalak
내가 편집했습니다. 지금보십시오. – User501
여전히 들여 쓰이지 않습니다. 들여 쓰기되지 않은 코드는 읽을 수 없습니다. – Tomalak