2012-11-16 4 views
-1

내가 같은 입력 XML이 :XSTL 유지 순서

<group> 
    <item> 
    <id>item 1</id> 
    <CategoryName>blue</CategoryName> 
    <id>item 2</id> 
    <CategoryName>orange</CategoryName> 
    <id>item 3</id> 
    <CategoryName>green</CategoryName> 
</item> 
</group> 

을 내가

<group> 
<item> 
    <itemNode><id>item 1</id><itemNode> 
    <Color>blue</Color> 
    <itemNode><id>item 2</id><itemNode> 
    <Color>orange</Color> 
    <itemNode><id>item 3</id><itemNode> 
    <Color>green</Color> 
</item> 

내가 XPath를 사용하도록 변환하려면, 먼저 itemNodes 태그를 보여줍니다 그 다음 색상 태그는 있지만 데이터가 원본으로 들어간 순서가 아닙니다.

어떻게 변형 할 수 있는지 아이디어는 있지만 여전히 시퀀스가?

+0

xslt를 게시 할 수 있습니까? – xiaoyi

+0

그래서, 당신은 "잊은"주요 데이터 ??? –

답변

0
<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="item"> 
<group> 
    <item> 
    <xsl:for-each select="id"> 
     <xsl:variable name="pos" select="position()" /> 
     <itemNode><id><xsl:value-of select="."/></id></itemNode> 
     <color><xsl:value-of select="../CategoryName[$pos]"/></color> 
    </xsl:for-each> 
    </item> 
</group> 
</xsl:template> 
</xsl:stylesheet> 
+0

xiaoyi, 감사합니다! 당신 솔루션 작품은,하지만 난 얘기를 깜빡 했네요 한 것은 ID입니다 및 범주는 다음과 같이 repeatitive 수 : 항목 1 항목 1.1 <범주> 블루 항목이 항목 2 항목 2 <범주> 오렌지 항목 3 항목 3.1 <범주> 그린

+0

xiaoyi, 당신은 업데이트 –

+0

@AtifSultanuddin 도와주세요 수 있습니다. – xiaoyi

관련 문제