나는 아래 XML을 가지고있다.조건이 될 필요가없는 곳으로 전화 받기
<?xml version="1.0" encoding="UTF-8"?>
<body>
<para><content-style font-style="bold">18/8/7</content-style> <content-style font-style="italic">(2) Here is the content</content-style>—Contributory negligence accident
<content-style font-style="italic">second v/w datav. </content-style> </para>
</body>
및 아래의 XSL. 여기
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<hmtl>
<head>
<title>New Version!</title>
</head>
<xsl:apply-templates/>
</hmtl>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="para[node()[position() = 1 and self::content-style[matches(., '(\w+)/(\w+)')]]]">
<div class="para">
<xsl:analyze-string select="." regex="(\w+)/(\w+)/(\w+)">
<xsl:matching-substring>
<a name="{concat('P',regex-group(1),'-',regex-group(2),'-',regex-group(3))}"/>
<span class="phrase">
<xsl:value-of select="."/>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="(\w+)/(\w+)">
<xsl:matching-substring>
<a name="{concat('P',regex-group(1),'-',regex-group(2))}"/>
<span class="phrase">
<xsl:value-of select="."/>
</span>
<xsl:text>     </xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
<xsl:apply-templates select="child::node()[not(self::content-style[1]/text())]"/>
</div>
</xsl:template>
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="./@format">
<span class="format-{@format}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',@font-style)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:apply-templates/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>
내가 정규식이 모두 content-styles
에서 호출지고있다 직면하고있는 문제,하지만 난 그것은 단지에 즉 단지에는 앞의 데이터 (텍스트 또는 노드)이없는 content-style
에서 호출 할 노드는 <para><content-style>
과 같지만 <para>(text/node)<content-style>
은 아닙니다.
현재 O의/피 :
<div class="para"><a name="P18-8-7"></a><span class="phrase">18/8/7</span> (2) Here is the content—Contributory negligence accident
second <span class="font-style-italic">second v/w datav.</span>
</div>
은 알려 주시기 바랍니다
<div class="para"><a name="P18-8-7"></a><span class="phrase">18/8/7</span> (2) Here is the content—Contributory negligence accident
second <a name="Pv-w"></a><span class="phrase">v/w</span> datav. —Contributory negligence accident
</div>
예상 O/P는 어디에서 잘못되어 가고이고 나는이 문제를 어떻게 해결할 수 있습니다. Working Demo
감사
나는이 모든 것의 논리를 이해하지 못한다고 생각합니다. 우선, 귀하의 실무 데모를 질문과 일치 시키십시오. 그것은 SO 질문과는 다른 입력과 템플릿을 가지고 있습니다. 그런 다음'para '와 일치하는 템플릿이 왜 두 개 있는지, 왜 이름이 템플릿인지, 왜'analyze-string'이 필요한지 설명하십시오. –
안녕하세요 @ MathiasMüller, 응답 주셔서 감사합니다, 왜냐하면 내가 정규 표현식과 일치하는'content-style'에서 문구를 만들고 싶기 때문에이 정규 표현식을 사용합니다.이 구문은 목적을 연결하기위한 것일뿐입니다. 첫 번째 부분에서 ''을 선택하고 두 번째 부분은 ''과 일치하는 두 개의 일치가 있음을 나타내는 차별화를 보여줍니다.이 점을 지적 해 주셔서 감사합니다. 문제. –
user3872094
여전히 일관성이 없습니다. 'para'와 일치하는 첫 번째 템플릿을 제거했지만, 이제'@ align' 속성에 대한 부분은 사라졌습니다. 더 이상 중요하지 않습니까? '콘텐츠 스타일'이 첫 아이가 아닌 '파라'엘리먼트는 어떻게 될까요? 출력 샘플은 여전히'body' 또는'html'을 가지고 있지 않습니다. 원하든 원하지 않습니까? –