使用xsl存储xml条目

时间:2017-07-11 12:37:11

标签: javascript xml xslt

我有这段代码可以避免我的网页运行。我收到有关尝试从xml文件检索数据并将其保存到gnSearchSettings.gnStores的行的错误。

 <xsl:if test="$angularApp = 'gn_search'">
  <script type="text/javascript">
    var module = angular.module('gn_search');
    module.config(['gnViewerSettings', 'gnGlobalSettings','gnSearchSettings',
    function(gnViewerSettings, gnGlobalSettings, gnSearchSettings) {
    <xsl:if test="$owsContext">
      gnViewerSettings.owsContext = '<xsl:value-of select="$owsContext"/>';
    </xsl:if>
    <xsl:if test="$wmsUrl and $layerName">
      gnViewerSettings.wmsUrl = '<xsl:value-of select="$wmsUrl"/>';
      gnViewerSettings.layerName = '<xsl:value-of select="$layerName"/>';
      gnViewerSettings.layerGroup = '<xsl:value-of select="$layerGroup"/>';
    </xsl:if>
    gnViewerSettings.mapConfig = <xsl:value-of select="$mapConfig"/>;
    gnGlobalSettings.isMapViewerEnabled = <xsl:value-of select="$isMapViewerEnabled"/>;
    gnViewerSettings.bingKey = '<xsl:value-of select="$bingKey"/>';
    gnSearchSettings.gnStores = [<xsl:apply-templates select="/root/gui/schemas/iso19139/codelists/codelist[@name='gmd:MD_TopicCategoryCode']/entry" mode="js-translations-topicCat"/>];

    }]);
  </script>
</xsl:if>

实际上,我有几个不同语言的xml文件。以下是我的一个名为codelists.xml的xml文件的一部分:

<codelist name="gmd:MD_TopicCategoryCode">
<entry>
  <code>farming</code>
  <label>Farming</label>
  <description>Rearing of animals and/or cultivation of plants. Examples: agriculture,
    irrigation, aquaculture, plantations, herding, pests and diseases affecting crops and
    livestock
  </description>
</entry>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - -->
<entry>
  <code>biota</code>
  <label>Biota</label>
  <description>Flora and/or fauna in natural environment. Examples: wildlife, vegetation,
    biological sciences, ecology, wilderness, sealife, wetlands, habitat
  </description>
</entry>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - -->
<entry>
  <code>boundaries</code>
  <label>Boundaries</label>
  <description>Legal land descriptions. Examples: political and administrative
    boundaries
  </description>
</entry>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - -->
<entry>
  <code>climatologyMeteorologyAtmosphere</code>
  <label>Climatology, meteorology, atmosphere</label>
  <description>Processes and phenomena of the atmosphere. Examples: cloud cover, weather,
    climate, atmospheric conditions, climate change, precipitation
  </description>
</entry>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - -->
<entry>
  <code>economy</code>
  <label>Economy</label>
  <description>Economic activities, conditions and employment. Examples: production, labour,
    revenue, commerce, industry, tourism and ecotourism, forestry, fisheries, commercial or
    subsistence hunting, exploration and exploitation of resources such as minerals, oil and
    gas
  </description>
</entry></codelist>

和xsl模板:

<xsl:template match="*" mode="js-translations">
"<xsl:value-of select="name(.)"/>":"<xsl:value-of
select="normalize-space(translate(.,'&quot;', '`'))"/>"
<xsl:if test="position()!=last()">,</xsl:if>

当我查看chrome的inspect webtool时,我收到此错误:“Uncaught SyntaxError:Unexpected identifier”在下图中突出显示的部分。实际上,您在此图像中看到的是从我的XML中检索到的数据。 我该如何解决这个问题?       enter image description here

0 个答案:

没有答案