Standard for "loops" in XML?

I am designing a simple XML file for animation. I often get into the situation that I write something like this:

<frame>
    <image>./image1.png<image/>
</frame>
<frame>
    <image>./image2.png<image/>
</frame>
<frame>
    <image>./image3.png<image/>
</frame>
...

Now this, of course, can be annoying. Therefore, I would think that this allows:

<frameset min=1 max=5>
    <image>./image#.png<image/>
</frameset>

Create # placeholder for the counter variable. What interests me is: is there already a standardized way to do something like this? It just makes things easier if you use methods that people are already used to.

Thank!

+3
source share
6 answers

There is no universal model, but what you are looking for is essentially a template solution - a template language and a template evaluation engine that converts a template to final XML by executing the code embedded in the template.

, , .

- , , , ; . . JSP Java, EmbPerl Perl, XSLT ..

EmbPerl:

[$ foreach my $i (1..5) $]
<frame>
    <image>./image[+$i+].png<image/>
</frame>
[$ endforeach $]

, , , (Perl vs. Java vs. xxx)


homebrew-, , , XML, -

<frameset min=1 max=5>
    <image part=1 conent_type="constant">./image<image/>
    <image part=2 conent_type="iterator_value"><image/>
    <image part=3 conent_type="constant">.png<image/>
</frameset>
+2

XML - . - xml, . :

<frameset>
<start>1</start>
<end>3</end>
<prefix>./image</prefix>
<suffix>.png</prefix>

.

+2

, "" .

, , - , () . , "-".

, XML , " ", , XSLT , .

( ) , , , , mark up "loop through" " " .

XML - , - , . , .

+2

XSLT, XML .

<frameset min=1 max=5> XSLT

<xsl:template match="iframe">
    <xsl:variable name="from" select="./@min"/>
    <xsl:variable name="to" select="./@max"/>
    --> loop from the ${from} to the ${to} variable, 
</xsl:template match="iframe">

XSLT

+1

, XML, . , .

XML, , .

, " " .

0

You can use XSLT for this, but it requires a conversion mechanism. Many of them are around (including in most browsers, for example). You can include the conversion declaration in the preprocessing directive of this document if you need to.

(It depends on the context in which you use your XML documents.)

0
source

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


All Articles