Convert and merge * .xml

I want to output a series of relationships from xml files and convert them to a graph that I generate with a dot. I obviously can do this with a script, but I was curious if this is possible with xslt. Sort of:

xsltproc dot.xsl *.xml

which will create a file of type

diagraph {
 state -> state2
 state2 -> state3
 [More state relationships from *.xml files]
}

Therefore, I need to: 1) wrap the combined xml transforms using "diagraph {...}" and 2) be able to process an arbitrary set of XML documents specified on the command line.

Is it possible? Any pointers?

+4
source share
2 answers

Using XSLT 2.0 and collection()it is really easy .

The following is an example of using Saxon :

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
    <xsl:output omit-xml-declaration="yes" indent="yes"/>

    <xsl:param name="pDirName" select="'D:/Temp/xmlFilesDelete'"/>

    <xsl:template match="/">
    <wrap>
        <xsl:apply-templates select=
         "collection(
                    concat('file:///',
                            $pDirName,
                            '?select=*.xml;recurse=yes;on-error=ignore'
                             )
                         )/*
          "/>
      </wrap>
    </xsl:template>

    <xsl:template match="*">
      <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>

XML- ( ), xml , , $pDirName.

, , xml:

<apples>3</apples>

<oranges>3</oranges>

:

<wrap>
   <apples>3</apples>
   <oranges>3</oranges>
</wrap>

, . , , Saxon. Saxon .

+8

All Articles