Actually XSLT Lookup (store variables during the loop and use a different template in it)

This question really asks something completely different . See Comments to @Tomalak's answer for an understanding of what OP really needs. :(

Is there a way to save the / param variable during the for-each loop as an array and use it in another template, namely <xsl:template match="Foundation.Core.Classifier.feature">. All values classnamethat appear during each of them must be saved. How would you implement this in XSLT? Here is my current code.

<xsl:for-each select="Foundation.Core.Class">       
 <xsl:for-each select="Foundation.Core.ModelElement.name">
  <xsl:param name="classname">
   <xsl:value-of select="Foundation.Core.ModelElement.name"/>
  </xsl:param>
 </xsl:for-each>
 <xsl:apply-templates select="Foundation.Core.Classifier.feature" /> 
</xsl:for-each>

Here is the template in which the parameters should be used classname.

<xsl:template match="Foundation.Core.Classifier.feature">
 <xsl:for-each select="Foundation.Core.Attribute">
  <owl:DatatypeProperty rdf:ID="{Foundation.Core.ModelElement.name}">
   <rdfs:domain rdf:resource="$classname" />
  </owl:DatatypeProperty>
 </xsl:for-each>
</xsl:template>

The input file can be found at http://krisvandenbergh.be/uml_pricing.xml

0
source share
2

, for-each .

, XSLT ( ), . , for-each, .

XSLT , , . <xsl:for-each> 98% , , XSLT. XSLT, <xsl:for-each>, ( , ), :

<xsl:template match="Foundation.Core.Class">
  <xsl:apply-templates select="
    Foundation.Core.Classifier.feature/Foundation.Core.Attribute
  " />
</xsl:template>

<xsl:template match="Foundation.Core.Attribute">
  <owl:DatatypeProperty rdf:ID="{Foundation.Core.ModelElement.name}">
    <rdfs:domain rdf:resource="{
      ancestor::Foundation.Core.Class[1]/Foundation.Core.ModelElement.name[1]
    }" />
  </owl:DatatypeProperty>
</xsl:template>

( , , , .)

XPath ancestor , ( , <Foundation.Core.ModelElement.name> ).

PS: XML - . ... ... , , <Foundation.Core.Classifier.feature>. , - .


:

xmi.id/xmi.idref, - XSL-:

<!-- this indexes all elements by their @xmi.id attribute -->
<xsl:key name="kElementByIdref" match="*[@xmi.id]" use="@xmi.id" />

<!-- now you can do this -->
<xsl:template match="Foundation.Core.DataType">
  <dataTypeName>
   <!-- pull out the corresponding element from the key, output its value -->
   <xsl:value-of select="key('kElementByIdref', @xmi.idref)" />
  </dataTypeName>
</xsl:template>

, , , . , , JavaScript.

+5

, , for-each . .

<Foundation.Core.DataType xmi.id="UID71848B1D-2741-447E-BD3F-BD606B7FD29E">
<Foundation.Core.ModelElement.name>int</Foundation.Core.ModelElement.name>
</Foundation.Core.DataType>

id UID71848B1D-2741-447E-BD3F-BD606B7FD29E

.

    <Foundation.Core.StructuralFeature.type>
<Foundation.Core.DataType xmi.idref="UID71848B1D-2741-447E-BD3F-BD606B7FD29E"/>
</Foundation.Core.StructuralFeature.type>

, . "int", , - . idref="UID71848B1D-2741-447E-BD3F-BD606B7FD29" int, Foundation.Core.ModelElement.name.

- , . , XSLT. - , , - , . ?

, , , .

-1

Source: https://habr.com/ru/post/1745884/


All Articles