2013-07-02 41 views
0

我对XSL相当陌生,我试图更改和合并元素。我需要使用XML InDesign中使用XSLT更改和合并XML中的元素

前:

<?xml version="1.0" encoding="UTF-8" ?> 
<catalog> 
    <node> 
     <Surname>Smith</Surname> 
     <Name>Paul</Name> 
     <Address1>New York</Address1> 
     <Address2>Los Angeles</Address2> 
    </node> 
    <node> 
     <Surname>White</Surname> 
     <Name>John</Name> 
     <Address1>San Francisco</Address1> 
     <Address2>Miami</Address2> 
    </node> 
</catalog> 

后:

<?xml version="1.0" encoding="UTF-8" ?> 
<catalog> 
    <node> 
     <Name>Paul Smith</Name> 
     <Address2>Los Angeles</Address2> 
     <Address1>New York</Address1> 
    </node> 
    <node> 
     <Name>John White</Name> 
     <Address2>Miami</Address2> 
     <Address1>San Francisco</Address1> 
    </node> 
</catalog> 

我不知道我怎样才能做到这一点。

THX对您有所帮助

+0

您是否有示例XSLT,显示您已尝试执行的操作? – 2013-07-03 03:25:12

+0

不,我没有。我正在阅读这个有趣网站的很多答案,但我无法达成解决方案。 –

回答

0

这XSLT应该做你需要的东西,虽然它不重新排序地址。他们必须重新排序吗?

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:template match="/"> 
    <xsl:apply-templates /> 
</xsl:template> 
<xsl:template match="node"> 
    <node> 
     <xsl:apply-templates select="Name"/> 
     <xsl:apply-templates select="Address2"/> 
     <xsl:apply-templates select="Address1"/> 
    </node> 
</xsl:template> 
<xsl:template match="Name"> 
    <Name> 
     <xsl:value-of select="."/> 
     <xsl:text> </xsl:text> 
     <xsl:value-of select="../Surname"/> 
    </Name> 
</xsl:template> 
<xsl:template match="Surname" /> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 
+0

谢谢你的帮助。 是的,他们应该重新排序。 –

+0

在这种情况下,更新应该做你需要的。 – 2013-07-03 08:13:55

+0

:)非常感谢! –