2014-01-21 1 views
0

I가 (AN XElement를 저장한다)이 문자열을 갖도록 변형 :XML은 속성의 요소

<MergeFields xmlns="urn:www-xxx-com:schema.xx-calls"> 
    <MergeField name="XAccountID" value="1234" /> 
    <MergeField name="XDate" value="01/20/2013 10:00:00 AM" /> 
</MergeFields> 

Mergefields 다른 속성을 저장한다.

<MergeFields> 
    <XAccountID>1234</XAccountID> 
    <XDate>01/20/2013 10:00:00</XDate> 
</MergeFields> 

내가 XSLT 사용에 대한 읽었습니다,하지만 난 샘플 코드를 찾는 힘든 시간을 보내고 있습니다 :

나는 다음과 같은 문자열로 변환해야합니다. 어떻게해야합니까?

답변

2

IBM의 DeveloperWorks 웹 사이트에 좋은 XSLT 자습서가 있다고 생각합니다. 나는 그것들을 읽는 것을 권할 것이다. 그들은 예제를 포함해야합니다.

일반적으로 정답은 정체성 변환으로 시작하는 것입니다. 그런 다음 예외적 인 경우를 처리하는 템플릿 을 추가하십시오.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <!-- Identity: Copy all nodes unchanged, recursively --> 
    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <!-- Exception: Attributes of MergeFields should be turned into elements 
     with the same name and value --> 
    <xsl:template match="MergeFields/@*"> 
    <xsl:element name="name()"><xsl:value-of select="."/></xsl:element>  
    </template> 

</xsl:stylesheet>