我正在尝试使用 XSL 样式表使用 Transform.xsl 文件将 Source.xml 文件转换为 Desired.xml 格式。除了节点中的命名空间属性外,我设法正确地对其进行了转换。有谁知道我需要在 xsl 转换文件中添加什么来添加该属性?
所需的.xml
<?xml version="1.0"?>
<XML_FAX_SUBMIT java="0" xmlns="x-schema:C:\rf\XML_FAX_SUBMIT_schema.xml" stylesheet="C:\rf\XML_FAX_SUBMIT.XSL">
<SENDER>
<FROM_NAME>John Public</FROM_NAME>
<RF_USER>JOHN</RF_USER>
</SENDER>
<DESTINATIONS>
<FAX unique_id="1">
<TO_FAXNUM>1234</TO_FAXNUM>
<TO_NAME>Public</TO_NAME>
<TO_COMPANY>ACME</TO_COMPANY>
<NOTIFY_HOST SuccessTemplate="1.inc" FailureTemplate="2.inc" Name="NotifyImportServer"/>
</FAX>
</DESTINATIONS>
<ATTACHMENT>
<FILE path="c:\test\test.tif"/>
</ATTACHMENT>
</XML_FAX_SUBMIT>
源代码.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DrivveImage>
<Documents>
<Document Profile="Test" Profile-ID="0xA84E80AD7068B048B1B99E12E258F1B3" File="test.tif" Destination="C:\test" ImageFilePath="C:\test\test.tif" Pages="1">
<Fields>
<Field Name="FROM_NAME">John Public</Field>
<Field Name="RF_USER">JOHN</Field>
<Field Name="TO_FAXNUM">1234</Field>
<Field Name="TO_NAME">Public</Field>
<Field Name="TO_COMPANY">ACME</Field>
<Field Name="UNIQUE_ID">1</Field>
</Fields>
</Document>
</Documents>
</DrivveImage>
转换.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" media-type="text/xml" indent="yes"/>
<xsl:template match="/DrivveImage/Documents/Document">
<xsl:element name="XML_FAX_SUBMIT">
<xsl:attribute name="stylesheet">
<xsl:value-of select="string('C:\RF\XML_FAX_SUBMIT.XSL')"/>
</xsl:attribute>
<xsl:attribute name="java">
<xsl:value-of select="0"/>
</xsl:attribute>
<SENDER>
<FROM_NAME>
<xsl:value-of select="Fields/Field[@Name='FROM_NAME']"/>
</FROM_NAME>
<RF_USER>
<xsl:value-of select="Fields/Field[@Name='RF_USER']"/>
</RF_USER>
</SENDER>
<DESTINATIONS>
<FAX>
<xsl:attribute name="unique_id">
<xsl:value-of select="Fields/Field[@Name='UNIQUE_ID']"/>
</xsl:attribute>
<TO_FAXNUM>
<xsl:value-of select="Fields/Field[@Name='TO_FAXNUM']"/>
</TO_FAXNUM>
<TO_NAME>
<xsl:value-of select="Fields/Field[@Name='TO_NAME']"/>
</TO_NAME>
<TO_COMPANY>
<xsl:value-of select="Fields/Field[@Name='TO_COMPANY']"/>
</TO_COMPANY>
<NOTIFY_HOST SuccessTemplate="1.inc" FailureTemplate="1.inc" Name="NotifyImportServer" />
</FAX>
</DESTINATIONS>
<xsl:element name="ATTACHMENT">
<FILE>
<xsl:attribute name="path"><xsl:value-of select="@Destination"/>\<xsl:value-of select="@File"/></xsl:attribute>
</FILE>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
提前致谢。