Xml 使用XSLT向上移动节点
我做了很多搜索,但我不知道如何准确地使用模板 我的输入数据称为DEBTORS.xml:Xml 使用XSLT向上移动节点,xml,xslt,Xml,Xslt,我做了很多搜索,但我不知道如何准确地使用模板 我的输入数据称为DEBTORS.xml: <?xml version="1.0" ?> <eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd"> <Accounts> <Account code=" 001"
<?xml version="1.0" ?>
<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd">
<Accounts>
<Account code=" 001" status="A" type="C">
<Name>Name</Name>
<Contacts>
<Contact default="1" gender="M" status="A">
<Note>Patient: 1</Note>
<FirstName></FirstName>
<Addresses>
<Address type="D" desc="">
<AddressLine1>Street</AddressLine1>
<AddressLine2></AddressLine2>
<AddressLine3></AddressLine3>
<PostalCode>0000 AA</PostalCode>
<City>'City</City>
<Country code="NL"/>
<Phone></Phone>
<Fax></Fax>
</Address>
</Addresses>
<Language code="NL"/>
<JobDescription>--</JobDescription>
<Phone></Phone>
<PhoneExt></PhoneExt>
<Fax></Fax>
<Mobile></Mobile>
<Email></Email>
<WebAccess>0</WebAccess>
</Contact>
</Contacts>
<Debtor number=" 1" code=" 1">
<Currency code="EUR"/>
</Debtor>
</Account>
</Accounts>
</eExact>
名称
病人:1
街头
0000 AA
&载脂蛋白;城市
--
0
我的XSL名为Test.XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Indentation in XSL -->
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<!-- Removing blank lines in XSL -->
<xsl:strip-space elements="*"/>
<!-- Identity rule -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- special rules ... -->
<xsl:template match="Contact">
<xsl:copy>
<!--
Apply the attributes of the current node and the attributes of all
childs
-->
<xsl:apply-templates select="@* | child::node()[not(self::Note)]"/>
</xsl:copy>
<xsl:apply-templates select="Note"/>
</xsl:template>
</xsl:stylesheet>
需要输出:
<?xml version="1.0" ?>
<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd">
<Accounts>
<Account code=" 868" status="A" type="C">
<Name>Name</Name>
<Contacts>
<Contact default="1" gender="M" status="A">
<FirstName></FirstName>
<Addresses>
<Address type="D" desc="">
<AddressLine1>Street</AddressLine1>
<AddressLine2></AddressLine2>
<AddressLine3></AddressLine3>
<PostalCode>0000 AA</PostalCode>
<City>'City</City>
<Country code="NL"/>
<Phone></Phone>
<Fax></Fax>
</Address>
</Addresses>
<Language code="NL"/>
<JobDescription>--</JobDescription>
<Phone></Phone>
<PhoneExt></PhoneExt>
<Fax></Fax>
<Mobile></Mobile>
<Email></Email>
<WebAccess>0</WebAccess>
</Contact>
</Contacts>
<Note>Patient: 1</Note>
<Debtor number=" 1" code=" 1">
<Currency code="EUR"/>
</Debtor>
</Account>
</Accounts>
</eExact>
名称
街头
0000 AA
&载脂蛋白;城市
--
0
病人:1
我的问题是,在XSL中,节点“Note”作为contact的子节点出现,但我希望它作为account的子节点出现。希望有人能帮助我
我的问题是,在XSL中,节点“Note”作为
联系,但我希望它作为帐户的子项
那么,您需要将其从联系人中排除,并将其包括在帐户中:
XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<!-- Identity rule -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- special rules ... -->
<xsl:template match="Contact">
<xsl:copy>
<!-- exclude Note -->
<xsl:apply-templates select="@* | node()[not(self::Note)]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Account">
<xsl:copy>
<!-- include Note -->
<xsl:apply-templates select="@* | node() | Contacts/Contact/Note"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
谢谢!工作得很有魅力。