저는 아직 XSLT 초보자이지만 어려운 작업을하고 있습니다.복잡한 XSL 변환
변환 할 필요가있는 비 xml 파일이 있습니다. 파일의 형식은 s는 다음과 같습니다
type1
type1line1
type1line2
type1line3
type2
type2line1
type2line2
type3
type3line1
type3line2
유형 (type1, type2, ...
)는 특정 순서가없는 특정 코드를 사용하여 지정됩니다. 각 유형에는 아래에 복수 line
이 있습니다.
그래서이 파일을 변환해야하지만 문제는 각각 type
에 대해 기본 행마다 각각 다른 변환을해야한다는 것입니다.
이제 문자열을 한 줄씩 읽고 새로운 형식이 시작되었지만 기본 줄에서 플래그를 사용하여 형식을 나타내는 플래그를 설정하는 방법을 알 수 없습니다. 문제를 해결하는 방법에 대한
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:param name="testString" as="xs:string">
type1
line1
line2
type1
line1
</xsl:param>
<xsl:template match="/">
<xsl:call-template name="main">
<xsl:with-param name="testString" select="$testString"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="main">
<xsl:param name="testString"/>
<xsl:variable name="iniFile" select="$testString"/>
<config>
<xsl:analyze-string select="$iniFile" regex="\n">
<xsl:non-matching-substring>
<item>
<xsl:choose>
<xsl:when test="starts-with(., 'type1')">
<!-- do a specific transformation-->
</xsl:when>
<xsl:when test="starts-with(., 'type2')">
<!-- do another transformation-->
</xsl:when>
</xsl:choose>
</item>
</xsl:non-matching-substring>
</xsl:analyze-string>
</config>
</xsl:template>
</xsl:stylesheet>
어떤 생각을 : 여기
내가 지금 가지고있는 것입니다.
입니다. ** XSLT는 ** XML 파일 **을 변환하기위한 것입니까? ;) –
Niels와 같은 코멘트를 피하기 위해이 질문에 XSLT2로 태그를 답니다. @Niels van der Rest : XSLT2는 분석되지 않은 문서를 조작 할 수 있습니다. –
@Alejandro 저를 바로 잡아 주셔서 감사합니다. 나는 그 사실을 알지 못했습니다. –