2016-08-17 6 views
0

以下は入力XMLです。xmlタグの値をxsltのルートタグの一番下に移動

私はまた、リンクするための新しいIDを作成する必要が

...、両者が同じであれば、idaf1af2af3として生成する必要があり、affiliationラベル値でorfidタグ値と一致する必要が

mailid

<author-group> 

    <author> 

     <given-name>Lars</given-name> 

     <surname>Dammeier</surname> 

     <orfid>a</orfid> 

     <e-address type="email">[email protected]</e-address> 

    </author> 

    <author> 

     <given-name>Ren</given-name> 

     <surname>Schwonnek</surname> 

     <orfid>b</orfid> 

     <e-address type="email">[email protected]</e-address> 

    </author> 

    <affiliation><label>a</label>Trichy</affiliation> 

    <affiliation><label>b</label>Chennai</affiliation> 

</author-group> 

出力XMLは、私はあなたの入力XMLにrootという名前のルートタグを追加したとして、XSLT

<contrib-group content-type="all"> 

    <contrib contrib-type="author"> 

     <name> 

      <surname>Dammeier</surname> 

      <given-names>Lars</given-names> 

     </name> 

     <xref ref-type="aff" rid="af1"/> 

     <xref ref-type="aff" rid="em1"/> 

    </contrib> 

    <contrib contrib-type="author"> 

     <name> 

      <surname>Schwonnek</surname> 

      <given-names>Ren</given-names> 

     </name> 

     <xref ref-type="aff" rid="af2"/> 

     <xref ref-type="aff" rid="em2"/> 

    </contrib> 

    <aff id="af1">Trichy</country> 

    </aff> 

    <aff id="af2">Chennai</country> 

    </aff> 

    <ext-link ext-link-type="email" id="em1">[email protected]</ext-link> 

    <ext-link ext-link-type="email" id="em2">[email protected]</ext-link> 

</contrib-group> 
+0

** 1。**正確にあなたはこれにこだわっていますか?あなたのコードを最初から書くのではなく、修正できるように、あなたの試みを投稿してください。 - ** 2。** 'rid '値はどこから来るのでしょうか? –

+0

ridは、orfid値と所属/ラベルのいずれかが一致した場合、af1、af2、af3 ...と自動的に生成されます。 em1、em2と同じです...もし著者のメールアドレスがある場合 –

答えて

0

を用いて以下になります。おそらく、これはcontrib-groupタグだったはずです。

次のXSLTは、必要な作業を行います。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 

    <xsl:strip-space elements="*"/> 
    <xsl:output indent="yes"/> 

    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="author"> 
     <contrib> 
      <name> 
       <xsl:apply-templates select="surname"/> 
       <xsl:apply-templates select="given-name"/> 
      </name> 
      <xsl:apply-templates select="orfid"/> 
      <xsl:apply-templates select="e-address" mode="xref"/> 
     </contrib> 
    </xsl:template> 

    <xsl:template match="given-name"> 
     <given-names> 
      <xsl:apply-templates/> 
     </given-names> 
    </xsl:template> 

    <!-- orfids a-i, will have an id of af1-af9, if affiliations are more than 10, there is a need to recode --> 
    <xsl:template match="orfid"> 
     <xref ref-type="aff" rid="af{translate(., 'abcdefghi', '123456789')}"/> 
    </xsl:template> 

    <xsl:template match="e-address" mode="xref"> 
     <xref ref-type="aff" rid="em{count(preceding::e-address) + 1}"/> 
    </xsl:template> 

    <xsl:template match="e-address"> 
     <ext-link ext-link-type="email" id="em{count(preceding::e-address) + 1}"> 
      <xsl:value-of select="."/> 
     </ext-link> 
    </xsl:template> 

    <xsl:template match="affiliation"> 
     <aff id="af{translate(label, 'abcdefghi', '123456789')}"> 
      <xsl:apply-templates select="node()[not(self::label)]"/> 
     </aff> 
    </xsl:template> 

    <xsl:template match="root"> 
     <xsl:copy> 
      <xsl:apply-templates/> 
      <xsl:apply-templates select="descendant::e-address"/> 
     </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 
+0

Thanks joel。それは正しく動作します –

関連する問題