XSL样式表复制属性但添加SchemaLocation

时间:2016-07-22 18:33:43

标签: xml xslt

我正在创建一个传递架构属性的XML文件,但是我想使用XSL样式表添加xsi:schemaLocation。如何在文件及其属性上添加副本,但是添加schemaLocation?来自XML文件和下面样式表的示例代码。

我对XSL很新。任何帮助表示赞赏。

python test.py                                  
Enter a name: bill
Enter a name: bob
Enter a name:
{'bill': [], 'bob': []}
bill, who will win the fight? red
bob, who will win the fight? blue
Who won the fight? red
bill = Correct
bob = Incorrect
{'bill': ['red'], 'bob': ['blue']}

预期结果:

 let dateData = [("07-22-2016", 5.0), ("07-21-2016", 3), ("07-20-2016", 2), ("07-19-2016", 1), ("07-18-2016", 1), ("07-16-2016", 2), ("07-15-2016", 3)]

 var streaks:[(String,Bool,Int)] = []
 for (date,value) in dateData
 {
   if let goodMood = streaks.last?.1
      where goodMood == (value < 3)
   { streaks[streaks.count-1].2 += 1 }
   else
   { streaks += [(date, value<3, 1)] }
 }

 // at this point streaks contains an array of tupples with counts of consecutive days of a given mood
 //
 // [("07-22-2016", false, 2), ("07-20-2016", true, 4), ("07-15-2016", false, 1)]
 //
 // you can then process that as you need

 let goodStreaks = streaks.filter{$0.1}.map{($0.0,$0.2)}  // [("07-20-2016", 4)]
 let badStreaks  = streaks.filter{!$0.1}.map{($0.0,$0.2)} // [("07-22-2016", 2), ("07-15-2016", 1)]
 let longestGoodStreak  = streaks.filter{$0.1}.reduce(0, combine: { max($0,$1.2) }) // 4

1 个答案:

答案 0 :(得分:0)

AFAICT,预期结果可以非常简单地通过以下方式实现:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<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="/*">
    <xsl:copy>
        <xsl:attribute name="xsi:schemaLocation">www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo/PolizasPeriodo_1_1.xsd</xsl:attribute>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

相关问题