When is xsl: foreach really useful?

Can someone give an example when xsl: foreach is really useful?

I just made a project and came to the conclusion that everywhere I can replace it with an appropriate one <xsl:apply-templates />. <xsl:if>and <xsl:when/>sometimes make the code shorter, and I cannot effectively replace it <apply-templates/>in a functional style.

Is it <xsl:foreach>recognized harmful in any way?

Well, thanks to everyone, I really could not choose the answer among the best. I think it would be better to collect different cases.

Sorry for someone who denies the answers - it's not me :)

+3
source share
4 answers

<xsl:for-each> , , <xsl:for-each>,

, XSLT, , <xsl:for-each> "" PL , , <xsl:variable>.

<xsl:for-each> - , () , XML, , , XML-.

+4

. , , , , - , .

, , , . .

+5

, .

, XSLT <xsl:apply-templates> . <xsl:call-template>. , . <xsl:for-each>.

, . , , .

+2
source

I use for-each quite often because I have to create variables that are subsets of large xml files.

<xsl:variable name="foo">
  <xsl:for-each select="document('bar.xml')/item">
    <xsl:if test="baz = bax">
      <xsl:copy-of select="."/>
    </xsl:if>
  </xsl:for-each>
</xsl:variable>

Is this possible with a template?

Perhaps I am one of those programmers who cannot see the native way XSL does something ...

+1
source

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


All Articles