我正在尝试从我的 XML 制作 ONIX。这是 XSL 文件:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" mediatype="application/xml">
<xsl:output method="xml" encoding="utf-8" />
<xsl:template match="books">
<xsl:variable name="SentDate"><xsl:value-of select="translate(@timestamp,'- :','')" /></xsl:variable>
<ONIXMessage xmlns="http://www.editeur.org/onix/2.1/reference">
<Header>
<FromCompany>MyCompany</FromCompany>
<ToCompany>Google Play</ToCompany>
<SentDate><xsl:value-of select="substring($SentDate,1,string-length($SentDate) - 2)" /></SentDate>
</Header>
<xsl:apply-templates />
</ONIXMessage>
</xsl:template>
<xsl:template match="books/book">
<Product>
<RecordReference><xsl:value-of select="@id" /></RecordReference>
</Product>
</xsl:template>
这是用于转换的 XML:
<books xmlns:l="http://www.w3.org/1999/xlink" timestamp="2013-05-27 22:03:02">
<book id="1">...</book>
<book id="2">...</book>
<book id="3">...</book>
</books>
这是转换的结果:
<?xml version="1.0" encoding="utf-8"?>
<ONIXMessage xmlns="http://www.editeur.org/onix/2.1/reference" xmlns:xlink="http://www.w3.org/1999/xlink">
<Header>
<FromCompany>MyCompany</FromCompany>
<ToCompany>Google Play</ToCompany>
<SentDate>201305272203</SentDate>
</Header>
<Product xmlns="">
<RecordReference>1</RecordReference>
</Product>
<Product xmlns="">
<RecordReference>2</RecordReference>
</Product>
<Product xmlns="">
<RecordReference>3</RecordReference>
</Product>
</ONIXMessage>
所以,问题是:如何摆脱所有 Product 节点中的那些xmlns="" ?提前致谢。