비정형 방식으로 표 형식의 데이터를 보유하는 소스 HTML 파일을 처리하고 있습니다. 기본적으로 그것은 div
에 절대적으로 위치합니다. 내 목표는 일종의 구조화 된 XML 데이터를 다시 작성하는 것입니다. 내가 다음에 할 섹션으로 그룹 라인입니다 필요가있는 무엇, 그러나노드 집합이 변수에 저장 될 때 XSLT의 for-each-group 및 group-starting-with 특성을 사용하여 XML 요소 그룹화
<data>
<line top="44">
<item left="294">Some heading text</item>
</line>
<line top="47">
<item left="718">A</item> <!-- this item is a section-start -->
<item left="764">Section heading</item>
</line>
<line top="78">
<item left="92">Data</item>
<item left="144">Data</item>
<item left="540">Data</item>
<item left="588">Data</item>
</line>
<line top="101">
<item left="61">B</item> <!-- this item is a section-start -->
<item left="144">Section heading</item>
</line>
<line top="123">
<item left="92">Data</item>
<item left="144">Data</item>
</line>
</data>
: 지금까지, XSLT 2.0을 사용하여 나는이처럼 보이는 XML을 생성 할 수 있었다. 각 섹션은 첫 번째 항목의 값이 하나의 문자 A - Z로 구성된 줄로 시작됩니다. 내 접근 방식은 $lines
변수에 모든 <line>
요소를 보유한 다음 속성과 함께 xsl:for-each-group
을 사용하여 새 섹션을 시작하는 요소를 식별합니다.
각각의 XSLT 부분은 다음과 같습니다
<xsl:for-each-group select="$lines/line" group-starting-with="...pattern here...">
<section>
<xsl:copy-of select="current-group()"/>
</section>
</xsl:for-each-group>
문제는 내가 섹션의 시작을 식별하는 작업 패턴을 알아낼 수 없습니다입니다. 내가 할 수있는 가장 좋은 방법은 XPath 평가 기에서 별도로 사용할 때 //line/item[1]/text()[matches(., '^[A-Z]$')]
이 작동하는지 확인하는 것입니다. 그러나, 나는 group-starting-with
과 함께 사용할 수있는 작업 버전을 파생시킬 수 없습니다.
업데이트 따라서 원하는 결과는 다음과 같아야합니다
<data>
<section> <!-- this section started automatically because of being at the beginning -->
<line top="44">
<item left="294">Some heading text</item>
</line>
</section>
<section>
<line top="47">
<item left="718">A</item> <!-- this item is a section-start -->
<item left="764">Section heading</item>
</line>
<line top="78">
<item left="92">Data</item>
<item left="144">Data</item>
<item left="540">Data</item>
<item left="588">Data</item>
</line>
</section>
<section>
<line top="101">
<item left="61">B</item> <!-- this item is a section-start -->
<item left="144">Section heading</item>
</line>
<line top="123">
<item left="92">Data</item>
<item left="144">Data</item>
</line>
</section>
</data>
그래서 원하는 결과는 무엇입니까? 누락되면 질문이 불분명 해집니다. –
@DimitreNovatchev 나는 xslt 조각에서 분명하다고 생각했다. 어쨌든 질문을 업데이트했습니다. –
@DimitreNovatchev 첫 번째 항목에 ** 단일 ** 문자 A - Z *가 포함 된 질문에 강조 표시된 부분을 강조하겠습니다. –