Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT如何基于描述值编辑KML Placemark样式_Xml_Xslt_Kml - Fatal编程技术网

Xml XSLT如何基于描述值编辑KML Placemark样式

Xml XSLT如何基于描述值编辑KML Placemark样式,xml,xslt,kml,Xml,Xslt,Kml,我是XSLT新手,我想编辑以下KML文件 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document id="doc"> <Schema name="Geographic_Placemarks"> <SimpleField name="Description" type="string" /> <

我是XSLT新手,我想编辑以下KML文件

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="doc">
<Schema name="Geographic_Placemarks">
  <SimpleField name="Description" type="string" />
  <SimpleField name="x" type="string" />
  <SimpleField name="y" type="string" />
</Schema>
<Folder>
  <name>Geographic_Placemarks</name>

     <Placemark>
    <name>Site 1</name>
    <description>23</description>
    <Style>
      <LineStyle>
        <color>ff0000ff</color>
      </LineStyle>
      <PolyStyle>
        <fill>0</fill>
      </PolyStyle>
    </Style>
    <ExtendedData>
      <SchemaData schemaUrl="#Geographic_Placemarks">
        <SimpleData name="x">571750    </SimpleData>
        <SimpleData name="y">4548250    </SimpleData>
      </SchemaData>
    </ExtendedData>
    <Polygon>
      <altitudeMode>clampToGround    </altitudeMode>
      <outerBoundaryIs>
        <LinearRing>
          <altitudeMode>clampToGround    </altitudeMode>
          <coordinates>11.1825432433631,45.6613329598511     11.1298128785963,45.7000370530753 11.1833198656477,45.6994951268141 11.1825432433631,45.6613329598511    </coordinates>
        </LinearRing>
      </outerBoundaryIs>
    </Polygon>
  </Placemark>

  <Placemark>
    <name>Site 2</name>
    <description>10</description>
    <Style>
      <LineStyle>
        <color>ff0000ff</color>
      </LineStyle>
      <PolyStyle>
        <fill>0</fill>
      </PolyStyle>
    </Style>
    <ExtendedData>
      <SchemaData schemaUrl="#Geographic_Placemarks">
        <SimpleData name="x">575750</SimpleData>
        <SimpleData name="y">4548250</SimpleData>
      </SchemaData>
    </ExtendedData>
    <Polygon>
      <altitudeMode>clampToGround</altitudeMode>
      <outerBoundaryIs>
        <LinearRing>
          <altitudeMode>clampToGround</altitudeMode>
          <coordinates>11.1825432433631,45.6613329598511     11.1833198656477,45.6994951268141 11.2337967406582,45.6989609013362 11.2329870100429,45.6607994408117 11.1825432433631,45.6613329598511      </coordinates>
        </LinearRing>
      </outerBoundaryIs>
      </Polygon>
     </Placemark>
  </Folder>
</Document>
</kml>

地理位置标记
场地1
23
ff0000ff
0
571750
4548250
攀爬地面
攀爬地面
11.1825432433631,45.6613329598511     11.1298128785963,45.7000370530753 11.1833198656477,45.6994951268141 11.1825432433631,45.6613329598511    
站点2
10
ff0000ff
0
575750
4548250
攀爬地面
攀爬地面
11.1825432433631,45.6613329598511     11.1833198656477,45.6994951268141 11.2337967406582,45.6989609013362 11.2329870100429,45.6607994408117 11.1825432433631,45.6613329598511      
特别是,我想根据描述值修改每个placemark的样式部分。如果“描述”值为23,我希望用以下方式替换样式部分:

<LineStyle>
    <color>ff0000ff</color>
</LineStyle>
<PolyStyle>
    <fill>0.5</fill>
    <color>ff0000ff</color>
</PolyStyle>
<LineStyle>
    <color>ff0000ff</color>
</LineStyle>
<PolyStyle>
    <fill>1</fill>
    <color>#ffff99</color>
</PolyStyle>

ff0000ff
0.5
ff0000ff
否则,如果“描述”值为10,我希望以这种方式替换样式部分:

<LineStyle>
    <color>ff0000ff</color>
</LineStyle>
<PolyStyle>
    <fill>0.5</fill>
    <color>ff0000ff</color>
</PolyStyle>
<LineStyle>
    <color>ff0000ff</color>
</LineStyle>
<PolyStyle>
    <fill>1</fill>
    <color>#ffff99</color>
</PolyStyle>

ff0000ff
1.
#ffff99
换句话说,我想根据描述值更改KML布局

请帮我设置XSL好吗?提前谢谢

编辑以遵循您的建议我包括了xslt文件,但它的格式不好。正如我所说,我不太擅长XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:kml="http://www.opengis.net/kml/2.2">

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

  <xsl:template match="@* | node()">
    <xsl:for-each select="kml:Placemark">
    <xsl:variable name="Value" select="@description"/>
      <xsl:when test="$Value = '10'">
        <xsl:element name="$Style">

        <LineStyle>
            <color>ff0000ff</color>
            </LineStyle>
            <PolyStyle>
            <fill>1</fill>
            <color>#ffff99</color>
            </PolyStyle>

        </xsl:element>  
       </xsl:when>

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

ff0000ff
1.
#ffff99

我建议使用单个模板来替换需要更改的部分,而不是一个大的choose/when块。例如:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:kml="http://www.opengis.net/kml/2.2">
    <xsl:output method="xml"/>

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

    <!-- matches Style with sibling of description='23' -->
    <xsl:template match="kml:Style[../kml:description='23']">
        <Style>
            <LineStyle>
                <color>ff0000ff</color>
            </LineStyle>
            <PolyStyle>
                <fill>0.5</fill>
                <color>ff0000ff</color>
            </PolyStyle>
        </Style>
    </xsl:template>

    <!-- matches Style with sibling of description='10' -->
    <xsl:template match="kml:Style[../kml:description='10']">
        <Style>
            <LineStyle>
                <color>ff0000ff</color>
            </LineStyle>
            <PolyStyle>
                <fill>1</fill>
                <color>#ffff99</color>
            </PolyStyle>
        </Style>
    </xsl:template>

</xsl:stylesheet>

ff0000ff
0.5
ff0000ff
ff0000ff
1.
#ffff99

这当然可以进一步细化,例如,如果您实际上只是在更改PolyStyle,那么您可以编写模板来匹配该元素。

您到底在哪里处理这个问题?--另外,23和10是唯一可能的值吗?如果不是,那么当值不是这两个值时会发生什么呢?我从在线示例中尝试了几次编写xslt文件来实现这一点,但我不知道实现这一问题的基本语言语句。我仅将字符串('23'和'10')作为理解xslt结构的第一种简单而通用的方法,但理解如何计算相应的数字转换值也很有趣。例如,如何计算描述值(转换为数字)是否在25和50之间。thx for the patiencePost您的尝试,这样我们就可以修复它,而不必从头开始为您编写代码。@michael.hor257k ok posted