Xml 如何从XSL 3.0映射中获取字符串

Xml 如何从XSL 3.0映射中获取字符串,xml,xslt,xslt-3.0,Xml,Xslt,Xslt 3.0,我有一个XSL映射 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE stylesheet> <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/20

我有一个XSL映射

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE stylesheet>
<xsl:stylesheet version="3.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:functx="http://www.functx.com"  
    xmlns:map="http://www.w3.org/2005/xpath-functions/map">
    
    <xsl:param name="settings" select="'https://testurl.com' ||  '/_resources/includes/settings.xml'"/>
    
    <xsl:template name="sidenav">
        <map key="style" xmlns="http://www.w3.org/2005/xpath-functions">
            <xsl:choose>
                <xsl:when test="doc-available($settings)">
                    <string key="navcss" select="doc($settings)/document/settings/ouc:div[@label='section-menu-type']"/>
                </xsl:when>
                <xsl:otherwise>
                    <string key="navcss" select="$nav-css"/>
                </xsl:otherwise>
            </xsl:choose>
        </map>
        "style" : <xsl:value-of select="map:get('style')('navcss')"/>
    </xsl:template>
    <xsl:call-template name="sidenav"/>
</xsl:stylesheet>

“风格”:
当我尝试用下面的代码获取值时,我得到:“致命错误:未知类型映射”

“风格”:
如果我将其替换为:

<xsl:variable name="map" select="map {
    'navcss' : if(doc-available($settings)) then doc($settings)/document/settings/ouc:div[@label='section-menu-type'] else 'd3',            
}"/>
<xsl:value-of select="map:get($map, 'navcss')"/>


我得到了价值。我的问题是,你能创建一个map元素并得到它的键类似于map函数吗,还是只需要使用map xpath函数?

XSLT 3.0和xpath 3.1中定义的JSON的XML表示使用这样一个
map
元素来表示JSON对象,您可以使用
XML-to-JSON
将此类XML转换为JSON,并将其提供给
parse JSON
;另一方面,要在XSLT 3.0中创建映射,我建议使用
xsl:map
xsl:map条目
元素,或者只使用XPath 3.1表达式:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math"
    exclude-result-prefixes="#all"
    expand-text="yes"
    version="3.0">
    
  <xsl:param name="json-xml">
      <map xmlns="http://www.w3.org/2005/xpath-functions">
          <string key="foo">bar</string>
          <number key="pi">3.1415927</number>
      </map>
  </xsl:param>
  
  <xsl:variable name="map1" select="xml-to-json($json-xml) => parse-json()"/>
  
  <xsl:param name="map2" as="map(*)">
      <xsl:map>
          <xsl:map-entry key="'foo'" select="'bar'"/>
          <xsl:map-entry key="'pi'" select="math:pi()"/>
      </xsl:map>
  </xsl:param>
  
  <xsl:template match="root">
      <section>
          <h2>Example</h2>
          <p>{$map1?pi}</p>
          <p>{$map1?foo}</p>
      </section>
      <section>
          <h2>Example</h2>
          <p>{$map2?pi}</p>
          <p>{$map2?foo}</p>
      </section>
  </xsl:template>

我还没有详细说明所有映射属性,但我希望清楚如何在那里列出更多属性。

XSLT 3规范和XPath 3.1函数规范在函数名称空间中定义了
map
元素,它主要用于JSON的XML表示中,
JSON-to-XML
输出或
XML-to-JSON
作为其输入。因此,虽然XSLT可以在函数名称空间中有一个名为
map
的文本结果元素,但我不明白为什么您希望它可以通过
map:get('style')
访问,该函数希望XDM映射作为其第一个参数,然后是一个属性a,它是第二个属性。我曾尝试在@name='style'的顶部map元素中替换@key,然后我想创建map元素,以避免在xpath表达式中多次查询文件是否可用。e、 g.:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math"
    exclude-result-prefixes="#all"
    expand-text="yes"
    version="3.0">
    
  <xsl:param name="json-xml">
      <map xmlns="http://www.w3.org/2005/xpath-functions">
          <string key="foo">bar</string>
          <number key="pi">3.1415927</number>
      </map>
  </xsl:param>
  
  <xsl:variable name="map1" select="xml-to-json($json-xml) => parse-json()"/>
  
  <xsl:param name="map2" as="map(*)">
      <xsl:map>
          <xsl:map-entry key="'foo'" select="'bar'"/>
          <xsl:map-entry key="'pi'" select="math:pi()"/>
      </xsl:map>
  </xsl:param>
  
  <xsl:template match="root">
      <section>
          <h2>Example</h2>
          <p>{$map1?pi}</p>
          <p>{$map1?foo}</p>
      </section>
      <section>
          <h2>Example</h2>
          <p>{$map2?pi}</p>
          <p>{$map2?foo}</p>
      </section>
  </xsl:template>
select="if (doc-available($settings)) 
        then map { 'navcss' : doc($settings)/document/settings/ouc:div[@label='navcss'], 'navtype' :  doc($settings)/document/settings/ouc:div[@label='navtype']}
        else map { 'navcss' : 'd3', 'navtype' : 'sectionnav' }"