Select inline output using a result document in XSLT 2.0

Hello,

I am looking for a method to draw output in a result (output) document in XSLT. I know the method in which xsl:result-documentnode is created so that a single transformation is applicable to multiple documents. Usually this method uses several passes, for example:

<xsl:template match="/">
    <xsl:apply-templates select="*"/>
    <xsl:result-document href="test.xml">
        <xsl:apply-templates select="*"/>
    </xsl:result-document>
</xsl:template>

I am looking for a way to do this inline so that I can create two output documents in one pass. The reason is because I have a temporary tree that is created when the conversion that I want to output to the file is performed.

<xsl:variable name="treeBase">
    <Base/>
</xsl:variable>

<xsl:template match="/">
    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="these_elements">
    <xsl:param name="temp" select="$treeBase"/>


</xsl:template>

<xsl:template match="not_these_elements">
    <xsl:param name="temp" select="$treeBase"/>

    <xsl:apply-templates select="@*|node()">
       <xsl:with-param name="temp">
           <Base>
              <xsl:copy-of select="$temp/Base/*"/>
              <Item>
                  <xsl:value-of select="ThisItem"/>
              </Item>
           </Base>
        </xsl:with-param>
</xsl:template>

? XSLT . , , , . .

XSLT , ?

.

+3
1

, :

:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <!--                                               -->    
    <xsl:template match="/*">
      <xsl:variable name="vTop" select="."/>
  <!--                                               -->    
        <xsl:for-each-group select="num" group-by="xs:integer(.) mod 2">
          <xsl:result-document href="file:///C:/Temp/file{position()}.xml">
            <xsl:element name="{name($vTop)}">
              <xsl:copy-of select="current-group()"/>
            </xsl:element>
          </xsl:result-document>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

XML-

<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>010</num>
</nums>

: file1.xml file2.xml, num . p >

, " ", "", .

+1

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


All Articles