基本上,這是一個xlst新手,並且負責處理對處理德國市場電影元數據轉換的大型xls文件的一些更改。XLST 1.0更改值後的輸出中的組元素
XLS文件看起來是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:str="http://exslt.org/strings" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:redirect="http://xml.apache.org/xalan/redirect" extension-element-prefixes="redirect" xmlns:xalan="http://xml.apache.org/xslt" exclude-result-prefixes="xalan str">
<xsl:output method="xml" indent="yes" xalan:indent-amount="4"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/metadata">
<xsl:variable name="featureID" select="substring(mpm_product_id, 7, string-length(mpm_product_id))"/>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<Metadata>
<some values...>
<xsl:for-each select="genres/genre">
<Genre>
<xsl:choose>
<!-- Mappings for German Genres -->
<xsl:when test="/metadata/base/territory_code='DE'">
<xsl:choose>
<xsl:when test=".= 'Action'">Action und Abenteuer</xsl:when>
<xsl:when test=".= 'Adventure'">Action und Abenteuer</xsl:when>
<xsl:when test=".= 'Animation'">Zeichentrick</xsl:when>
<xsl:when test=".= 'Anime'">Zeichentrick</xsl:when>
<xsl:when test=".= 'Bollywood'">Bollywood</xsl:when>
<xsl:when test=".= 'Classics'">Drama > Klassiker</xsl:when>
<xsl:when test=".= 'Comedy'">Komödie</xsl:when>
<xsl:when test=".= 'Concert Film'">Musik</xsl:when>
<xsl:when test=".= 'Crime'">Kriminalfilm > Drama</xsl:when>
<xsl:when test=".= 'Drama'">Drama</xsl:when>
<xsl:when test=".= 'Fantasy'">Drama > Sci-Fi und Fantasy</xsl:when>
<xsl:when test=".= 'Foreign'">International</xsl:when>
<xsl:when test=".= 'Horror'">Kriminalfilm > Horror</xsl:when>
<xsl:when test=".= 'Independent'">Independentfilm & Arthouse</xsl:when>
<xsl:when test=".= 'Japanese Cinema'">International > Japan</xsl:when>
<xsl:when test=".= 'Jidaigeki'">International > Japan</xsl:when>
<xsl:when test=".= 'Kids & Family'">Kinderfilm > Familie</xsl:when>
<xsl:when test=".= 'Music Documentary'">Musik > Dokumentation</xsl:when>
<xsl:when test=".= 'Music Feature Film'">Musik</xsl:when>
<xsl:when test=".= 'Musicals'">Musik > Musical</xsl:when>
<xsl:when test=".= 'Mystery'">Drama > Mystery</xsl:when>
<xsl:when test=".= 'Nonfiction - Documentary'">Dokumentation</xsl:when>
<xsl:when test=".= 'Regional Indian'">International > Indien & Pakistan</xsl:when>
<xsl:when test=".= 'Romance'">Drama > Romanze</xsl:when>
<xsl:when test=".= 'Science Fiction'">Science Fiction und Fantasy</xsl:when>
<xsl:when test=".= 'Short Films'">Independentfilm & Arthouse > Experimentalfilm</xsl:when>
<xsl:when test=".= 'Special Interest'">Hobby</xsl:when>
<xsl:when test=".= 'Sports'">Sport</xsl:when>
<xsl:when test=".= 'Thrillers'">Thriller</xsl:when>
<xsl:when test=".= 'Tokusatsu'">International > Japan</xsl:when>
<xsl:when test=".= 'Urban'">Drama > Alltag</xsl:when>
<xsl:when test=".= 'Westerns'">Western</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</Genre>
</xsl:for-each>
<More values...>
</Metadata>
</xsl:template>
問題是當流派都改變了我們與例如重複值結束的時候,輸入包含的元素
<genres>
<genre>Comedy</genre>
<genre>Adventure</genre>
<genre>Action</genre>
</genres>
改造後我們有
<Genre>Komödie</Genre>
<Genre>Action und Abenteuer</Genre>
<Genre>Action und Abenteuer</Genre>
我試過尋找一些解決方案,但我還沒有達到解決方案和任何幫助將不勝感激。
編輯澄清:我需要的是從輸出中消除重複的流派元素。這些元素可以不相鄰,我們不能通過第二次轉換來運行輸出,因爲我們無法修改處理此操作的服務的代碼。
感謝
那麼你至少需要告訴我們你想要的結果。你想消除重複的流派元素?只有在他們相鄰的時候,你想這樣做嗎,就像你的樣本,或者他們是分開的?您是否考慮過鏈接兩個樣式表,您只需簡單地通過第二個樣式表運行輸出,以避免Muenchian分組重複出現http://www.jenitennison.com/xslt/grouping/muenchian.xml? – 2014-09-22 18:07:23
理想情況下,需要從列表中刪除重複的流派元素,這些元素並不總是彼此相鄰。也不可能通過第二個樣式表運行輸出。我將通過這些澄清更新這個問題。 – 2014-09-22 18:16:37
您將需要另一個包含「if」條目值的XML,因此您可以使用XPath檢查「前兄弟節點」。 – Xenos 2014-09-22 18:27:55