XSLT: reading a parameter that an XML document passes as a string

I ran into a problem with another engineer. As a new engineer, I have to find a solution to this, but I could not. Any help would be appreciated, the closest thing I found is a Chunk string with XSLT , but still not quite there. I can use XSL v1.0.

The parameter is passed to my stylesheet as a giant string. It was originally derived from an XML document. The line looks something like this.

C <xsl:value-of select="$servers"/>where $serversis the parameter for the string passed to me. The line looks like this:

<license><active_servers><server><name>MIKE</name><capacity>18</capacity><status>0</status><expiration></expiration><left>0</left><comment></comment></server><server><name>Susie</name><capacity>0</capacity><status>1</status><expiration>2014-07-04T00:00:00Z</expiration><left>5238568</left><comment></comment></server><server><name>Zoe</name><capacity>5000</capacity><status>1</status><expiration></expiration><left>0</left><comment></comment></server></active_servers></license>

This is the section of xml data passed as a parameter to the stylesheet. The actual document is 300 or so rows of data. The only distinguishing feature that separates these "nodes" are <server>and </server>. Is there a way to extract data from this if it is really a big row?

Say for example. I need to find "Zoya" and see if she has an "expiration", if she does not, I need her "status". So, Zoe will show the status “1”, since it does not have an expiration date. While MIKE displays "0" and Susie displays 2014-07-04T00: 00: 00Z.

google stack / . , . , , 2 , .

+3
2

XML XML. , , , , XSLT 1.0, - .

, XML- . , , , , , .

. :
fooobar.com/questions/935945/...

+2

XML, @michael.hor257k , node -set, . URI document(). XSLT 1.0 , , ( uri). XSLT 1.0, Xalan Saxon 6, .

, URI data:text/xml, . document() XML :

document(concat('data:text/xml,',$servers))

node -set.

$servers, , XML-. , XML :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes"/>
    <xsl:param name="servers"/>

    <xsl:template match="/">
        <xsl:apply-templates select="document(concat('data:text/xml,',$servers))/license"/>
    </xsl:template>

    <xsl:template match="license">
        <results>
            <xsl:apply-templates/>
        </results>
    </xsl:template>

    <!-- server without expiration - get status -->
    <xsl:template match="server[not(string(expiration))]">
        <server name="{name}" status="{status}" />
    </xsl:template>

    <!-- server with expiration - get expiration -->
    <xsl:template match="server">
        <server name="{name}" expiration="{expiration}" />
    </xsl:template>

</xsl:stylesheet>

, , :

<results>
   <server name="MIKE" status="0"/>
   <server name="Susie" expiration="2014-07-04T00:00:00Z"/>
   <server name="Zoe" status="1"/>
</results>

UPDATE: . , XML ​​, XSLT- . Oxygen XML Editor 15.2 Mac OS X. , , .

+3

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


All Articles