XSL 파일에 다음과 유사한 좌표가 포함되어 있습니다.
<coordinates>
12345,567,5
56777,444,1
67884,443,7
12345,567,5
<coordinates>
이제 좌표의 첫 번째 값을 마지막 값과 비교하고 싶습니다 (12345,567,5는 마지막 값과 같아야합니다). XSLT로 어떻게이 작업을 수행 할 수 있습니까?
이미 substring ()으로 값을 분할하려고 시도했지만 좌표의 길이는 가변적입니다.
음, 사용 tokenize
하여 선을 찾은 다음 비교하십시오.
<xsl:template match="coordinates">
<xsl:variable name="lines" select="tokenize(., '\r?\n')[normalize-space()]"/>
<xsl:copy>
<xsl:sequence select="$lines[1] = $lines[last()]"/>
</xsl:copy>
</xsl:template>
그래서 예를 들어
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="coordinates">
<xsl:variable name="lines" select="tokenize(., '\r?\n')[normalize-space()]"/>
<xsl:copy>
<xsl:sequence select="$lines[1] = $lines[last()]"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
예를 들어
<body>
<coordinates>
12345,567,5
56777,444,1
67884,443,7
12345,567,5
</coordinates>
<coordinates>
12345,567,5
56777,444,1
67884,443,7
12345,567,6
</coordinates>
</body>
출력
<body>
<coordinates>true</coordinates>
<coordinates>false</coordinates>
</body>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다