XSLT를 배우려고하지만 예제로 가장 잘 작동합니다. 간단한 스키마 - 스키마 변환을 수행하고 싶습니다. 이 변환은 단 한번의 패스로 어떻게 수행합니까 (현재 솔루션은 두 번의 패스를 사용하고 고객의 원래 순서를 잃습니다).for for eachin XSLT에서 다중 노드를 선택하는 방법
에서 :
<?xml version="1.0" encoding="UTF-8"?>
<sampleroot>
<badcustomer>
<name>Donald</name>
<address>Hong Kong</address>
<age>72</age>
</badcustomer>
<goodcustomer>
<name>Jim</name>
<address>Wales</address>
<age>22</age>
</goodcustomer>
<goodcustomer>
<name>Albert</name>
<address>France</address>
<age>51</age>
</goodcustomer>
</sampleroot>
에 :
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record id="customer">
<name>Donald</name>
<address>Hong Kong</address>
<age>72</age>
<customertype>bad</customertype>
</record>
<record id="customer">
<name>Jim</name>
<address>Wales</address>
<age>22</age>
<customertype>good</customertype>
</record>
<record id="customer">
<name>Albert</name>
<address>France</address>
<age>51</age>
<customertype>good</customertype>
</record>
</records>
내가 이미이에게 나쁜 방법으로 해결 (I는 고객의 주문을 잃고 난 파일을 구문 분석 할 필요가 있다고 생각 여러 번 :
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/sampleroot">
<records>
<xsl:for-each select="goodcustomer">
<record id="customer">
<name><xsl:value-of select="name" /></name>
<address><xsl:value-of select="address" /></address>
<age><xsl:value-of select="age" /></age>
<customertype>good</customertype>
</record>
</xsl:for-each>
<xsl:for-each select="badcustomer">
<record id="customer">
<name><xsl:value-of select="name" /></name>
<address><xsl:value-of select="address" /></address>
<age><xsl:value-of select="age" /></age>
<customertype>bad</customertype>
</record>
</xsl:for-each>
</records>
</xsl:template>
</xsl:stylesheet>
제발 누군가가 올바른 XSLT 구조로 나를 도우 려 할 수 있습니까? 단 하나의 구문 분석 만 사용해야합니다 (각각 하나씩).
감사합니다,
크리스
좋은 질문 Chris (+1). 좋은 해결책은 내 대답을 참조하십시오. :) –