[英]Move an XML element from its place, to under another parent element using xslt
[英]move xml tag to another place in xml and id generation using xslt
輸入XML
:
<author-group>
<author>
<given-name>aaa</given-name>
<surname>bbb</surname>
<orfid>a</orfid>
<e-address type="email">abc@gmail.com</e-address>
</author>
<affiliation>chennai</affiliation>
</author-group>
輸出XML
應為:
<contrib-group content-type="all">
<contrib contrib-type="author">
<name>
<given-name>aaa</given-name>
<surname>bbb</surname>
</name>
<xref ref-type="aff" rid="af1"/>
<xref ref-type="email" rid="em1"/>
</contrib>
<aff id="af1">chennai</aff>
<ext-link id="em1">abc@gmail.com</ext-link>
</contrib-group>
誰能幫助我使用XSLT將輸入XML
轉換為輸出XML
?
您好,歡迎來到Stackoverflow。
假設您的轉義標記只是一個錯誤,以下XSL將產生您要求的確切輸出。
但是,其中沒有“代”,因為我不知道您的意思是什么。 如果需要,請問一個更明確的問題。
<?xml version="1.0" encoding="utf-8"?>
<author-group>
<author>
<given-name>aaa</given-name>
<surname>bbb</surname>
<orfid>a</orfid>
<e-address type="email">abc@gmail.com</e-address>
</author>
<affiliation>chennai</affiliation>
</author-group>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="author-group">
<xsl:element name="contrib-group">
<xsl:attribute name="content-type">
<xsl:value-of select="'all'"/>
</xsl:attribute>
<xsl:element name="contrib">
<xsl:attribute name="contrib-type">
<xsl:value-of select="'author'"/>
</xsl:attribute>
<xsl:element name="name">
<xsl:copy-of select="./author/given-name"/>
<xsl:copy-of select="./author/surname"/>
</xsl:element>
<xsl:element name="xref">
<xsl:attribute name="ref-type">
<xsl:value-of select="'aff'"/>
</xsl:attribute>
<xsl:attribute name="rid">
<xsl:value-of select="'af1'"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="xref">
<xsl:attribute name="ref-type">
<xsl:value-of select="'email'"/>
</xsl:attribute>
<xsl:attribute name="rid">
<xsl:value-of select="'em1'"/>
</xsl:attribute>
</xsl:element>
</xsl:element
<xsl:element name="aff">
<xsl:attribute name="id">
<xsl:value-of select="'af1'"/>
</xsl:attribute>
<xsl:value-of select="./affiliation"/>
</xsl:element>
<xsl:element name="ext-link">
<xsl:attribute name="id">
<xsl:value-of select="'em1'"/>
</xsl:attribute>
<xsl:value-of select="./author/e-address"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<contrib-group content-type="all">
<contrib contrib-type="author">
<name>
<given-name>aaa</given-name>
<surname>bbb</surname>
</name>
<xref ref-type="aff" rid="af1" />
<xref ref-type="email" rid="em1" />
</contrib>
<aff id="af1">chennai</aff>
<ext-link id="em1">abc@gmail.com</ext-link>
</contrib-group>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.