具有此XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<root xmlns="http://www.edocu.com">
<page1>
<eDocuID>5a0b6b78</eDocuID>
<FormID>Test form</FormID>
</page1>
<page2>
<person>
<ssno>12345</ssno>
</person>
<address>
<ssno1>12345</ssno1>
<address_Street>Castle</address_Street>
<address_Number>22</address_Number>
<address_Letter>B</address_Letter>
<address_PostNo>1435</address_PostNo>
</address>
</page2>
</root>
使用此XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:edocu="http://www.edocu.com">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" encoding="UTF-8" standalone="yes" />
<xsl:variable name="schemaId" select="//edocu:eDocuID" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}" namespace="http://www.asdf.no/eDocu/{$schemaId}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
<xsl:template match="//edocu:address">
<xsl:variable name="aaa" select="//edocu:address_Street"/>
<xsl:variable name="bbb" select="//edocu:address_Number"/>
<xsl:variable name="ccc" select="//edocu:address_Letter"/>
<xsl:element name="new_element">
<xsl:value-of select="concat($aaa,$bbb,$ccc)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
结果XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root xmlns="http://www.asdf.no/eDocu/5a0b6b78">
<page1>
<eDocuID>5a0b6b78</eDocuID>
<FormID>Test form</FormID>
</page1>
<page2>
<person>
<ssno>12345</ssno>
</person>
<new_element xmlns="">Castle22B</new_element>
</page2>
</root>
我想做的是将三个元素(地址_街道,地址_编号和地址_字母)连接到第四个元素(新元素)中。很好,但是我的问题是:
答案 0 :(得分:0)
尝试一下:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:edocu="http://www.edocu.com"
exclude-result-prefixes="edocu">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="new-namespace" select="concat('http://www.asdf.no/eDocu/', //edocu:eDocuID)"/>
<xsl:template match="*">
<xsl:element name="{name()}" namespace="{$new-namespace}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="edocu:address">
<xsl:element name="address" namespace="{$new-namespace}">
<xsl:apply-templates/>
<xsl:element name="new_element" namespace="{$new-namespace}">
<xsl:value-of select="edocu:address_Street"/>
<xsl:value-of select="edocu:address_Number"/>
<xsl:value-of select="edocu:address_Letter"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>