2010-05-25 6 views
1

나는 XSLT Insert XML node at a specific position of an existing documentXSLT를 사용하여 XML을 다른 XML 파일에 어떻게 삽입합니까?

와 XML에 XML을 삽입하지만 두 그랜드 자식 노드 사이에 XML을 삽입해야하기 때문에 내가 문제가있는 방법을 찾아이 스레드를 바라 보았다. 예를 들어 나는이 파일을 당신의 도움에 대한

<root> 
    <child1> 
    <a>...</a> 
    <r>...</r> 
    <s>...</s> 
    <t>...</t> 
    <z>...</z> 
    </child1> 
</root> 

감사를 작성하려면이 파일

<root> 
    <child1> 
    <a>...</a> 
    <r>...</r> 
    <t>...</t> 
    <z>...</z> 
    </child1> 
</root> 

<r>...</r><t>...</t> 사이 <s>...</s>을 삽입 할.

+0

만 XSLT 기반 솔루션을 찾고 계십니까? 어때 그냥 xpath 및 일부 자바 코딩? –

답변

2

표준 "항등 변환"을 더한 템플릿 요소 <r> 일치, 그 후 <s>...</s> 삽입 :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="r"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    <s>...</s> 
    </xsl:template> 
</xsl:stylesheet> 
+0

그게 효과가있다. 고맙습니다. – Sandra

+0

답변자가 문제를 해결 한 경우 답안의 왼쪽 상단에있는 확인란을 클릭하여 "수락"으로 표시하는 것이 일반적입니다. –

관련 문제