我需要在xml标签之间创建空格。我输入xml如下所示
<?xml version="1.0" encoding="UTF-8"?>
<EPCISDocument schemaVersion="" creationDate="">
<EPCISHeader>
<StandardBusinessDocumentHeader>
<HeaderVersion/>
<Sender>
<Identifier Authority=""/>
<ContactInformation>
<Contact/>
<EmailAddress/>
<FaxNumber/>
<TelephoneNumber/>
<ContactTypeIdentifier/>
</ContactInformation>
</Sender>
<Receiver>
<Identifier Authority=""/>
<ContactInformation>
<Contact/>
<EmailAddress/>
<FaxNumber/>
<TelephoneNumber/>
<ContactTypeIdentifier/>
</ContactInformation>
</Receiver>
<DocumentIdentification>
<Standard/>
<TypeVersion/>
<InstanceIdentifier/>
<Type/>
<MultipleType/>
<CreationDateAndTime/>
</DocumentIdentification>
<Manifest>
<NumberOfItems/>
<ManifestItem>
<MimeTypeQualifierCode/>
<UniformResourceIdentifier/>
<Description/>
<LanguageCode/>
</ManifestItem>
</Manifest>
<BusinessScope>
<Scope>
<BusinessService>
<BusinessServiceName/>
<ServiceTransaction TypeOfServiceTransaction="" IsNonRepudiationRequired="" IsAuthenticationRequired="" IsNonRepudiationOfReceiptRequired="" IsIntegrityCheckRequired="" IsApplicationErrorResponseRequired="" TimeToAcknowledgeReceipt="" TimeToAcknowledgeAcceptance="" TimeToPerform="" Recurrence=""/>
</BusinessService>
<CorrelationInformation>
<RequestingDocumentCreationDateTime/>
<RequestingDocumentInstanceIdentifier/>
<ExpectedResponseDateTime/>
</CorrelationInformation>
</Scope>
</BusinessScope>
</StandardBusinessDocumentHeader>
</EPCISHeader>
<EPCISBody>
<EventList>
<ObjectEvent>
<eventTime/>
<recordTime/>
<eventTimeZoneOffset/>
<epcList>
<epc type=""/>
</epcList>
<action/>
<bizStep/>
<disposition/>
<readPoint>
<id/>
</readPoint>
<bizLocation>
<id/>
</bizLocation>
<bizTransactionList>
<bizTransaction type=""/>
</bizTransactionList>
<GskEpcExtension>
<nhrn> </nhrn>
</GskEpcExtension>
</ObjectEvent>
</EventList>
使用xslt代码我添加了几个前缀,下面是xslt代码
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:epcis="http://apse.com"
xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
xmlns:gsk="http://epcis.gsk.com">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="EPCISDocument">
<epcis:EPCISDocument>
<xsl:apply-templates select="node()|@*"/>
</epcis:EPCISDocument>
</xsl:template>
<xsl:template match="GskEpcExtension|GskEpcExtension//*">
<xsl:element name="gsk:{name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="StandardBusinessDocumentHeader|StandardBusinessDocumentHeader//*">
<xsl:element name="sbdh:{name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
输出我的代码正如预期的那样。但是我得到了新的要求,比如在gskepcextension节点下的输入xml中的一个字段nrn随附sapces。但是在输出xml中它的结尾就像gsk:/ nhrn。我需要像gsk:nhrn gsk:/ nhrn。如果值在该字段的输入中,则按预期填充。但是当它带有空格时,它不会按预期填充。任何人都可以帮助。例如,输出应该如下所示
<gsk:nhrn> </gsk:nhrn>
答案 0 :(得分:0)
删除<xsl:strip-space elements="*"/>
,然后您可能希望indent="no"
上有xsl:output
。