Skip to content

Commit bc767bb

Browse files
committed
Fix heredoc
1 parent d6a38bb commit bc767bb

File tree

2 files changed

+70
-61
lines changed

2 files changed

+70
-61
lines changed

src/class-xml-file.php

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -853,71 +853,70 @@ private function jsonToDomDocumentItem($el, $parent, $doc)
853853

854854
public static function saveJsonXsltStandard() {
855855
return <<<'EOC'
856-
<?xml version="1.0"?>
857-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
858-
<xsl:output method="text"/>
859-
<xsl:variable name='q'>"</xsl:variable>
860-
<!-- -->
861-
<xsl:template match="/">{
862-
<xsl:apply-templates select="*"/>}
863-
</xsl:template>
864-
<!-- -->
865-
<!-- Object or Element Property-->
866-
<xsl:template match="*">
867-
<xsl:value-of select='concat($q, name(), $q, ": ")' /><xsl:call-template name="Properties"/>
868-
</xsl:template>
869-
<!-- -->
870-
<!-- Array Element -->
871-
<xsl:template match="*" mode="ArrayElement">
872-
<xsl:call-template name="Properties"/>
873-
</xsl:template>
874-
<!-- -->
875-
<!-- Object Properties -->
876-
<xsl:template name="Properties">
877-
<xsl:variable name="childName" select="name(*[1])"/>
878-
<xsl:choose>
879-
<xsl:when test="not(*|@*)"><xsl:value-of select='concat($q, ., $q)' /></xsl:when>
880-
<xsl:when test="count(*[name()=$childName]) > 1"><xsl:value-of select='concat("{ ", $q, $childName, $q, ": ")' /> [<xsl:apply-templates select="*" mode="ArrayElement"/>] }</xsl:when>
881-
<xsl:otherwise>{
882-
<xsl:apply-templates select="@*"/>
883-
<xsl:apply-templates select="*"/>
884-
}</xsl:otherwise>
885-
</xsl:choose>
886-
<xsl:if test="following-sibling::*">,</xsl:if>
887-
</xsl:template>
888-
<!-- -->
889-
<!-- Attribute Property -->
890-
<xsl:template match="@*">
891-
<xsl:value-of select='concat($q, "@", name(), $q, ": ", $q, ., $q)' />
892-
<xsl:if test="following-sibling::*">,</xsl:if>
893-
</xsl:template>
894-
</xsl:stylesheet>
895-
896-
EOC;
856+
<?xml version="1.0"?>
857+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
858+
<xsl:output method="text"/>
859+
<xsl:variable name='q'>"</xsl:variable>
860+
861+
<xsl:template match="/">{
862+
<xsl:apply-templates select="*"/>}
863+
</xsl:template>
864+
865+
<!-- Object or Element Property-->
866+
<xsl:template match="*">
867+
<xsl:value-of select='concat($q, name(), $q, ": ")' /><xsl:call-template name="Properties"/>
868+
</xsl:template>
869+
870+
<!-- Array Element -->
871+
<xsl:template match="*" mode="ArrayElement">
872+
<xsl:call-template name="Properties"/>
873+
</xsl:template>
874+
875+
<!-- Object Properties -->
876+
<xsl:template name="Properties">
877+
<xsl:variable name="childName" select="name(*[1])"/>
878+
<xsl:choose>
879+
<xsl:when test="not(*|@*)"><xsl:value-of select='concat($q, ., $q)' /></xsl:when>
880+
<xsl:when test="count(*[name()=$childName]) > 1"><xsl:value-of select='concat("{ ", $q, $childName, $q, ": ")' /> [<xsl:apply-templates select="*" mode="ArrayElement"/>] }</xsl:when>
881+
<xsl:otherwise>{
882+
<xsl:apply-templates select="@*"/>
883+
<xsl:apply-templates select="*"/>
884+
}</xsl:otherwise>
885+
</xsl:choose>
886+
<xsl:if test="following-sibling::*">,</xsl:if>
887+
</xsl:template>
888+
889+
<!-- Attribute Property -->
890+
<xsl:template match="@*">
891+
<xsl:value-of select='concat($q, "@", name(), $q, ": ", $q, ., $q)' />
892+
<xsl:if test="following-sibling::*">,</xsl:if>
893+
</xsl:template>
894+
</xsl:stylesheet>
895+
EOC;
897896
}
898897

899898
public static function saveJsonXsltRecordset() {
900899
return <<<'EOC'
901-
<?xml version="1.0"?>
902-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
903-
<xsl:output method="text"/>
904-
<xsl:variable name='q'>"</xsl:variable>
905-
<!-- -->
906-
<xsl:template match="/recordset">
907-
<xsl:value-of select='concat("{", $q, @zname, $q, ": [")' />
908-
<xsl:for-each select='/*/row'>
909-
{
910-
<xsl:for-each select='field'>
911-
<xsl:value-of select='concat($q, @id, $q)' />: <xsl:value-of select='concat($q, ., $q)' />
912-
<xsl:if test="following-sibling::*">,</xsl:if>
913-
</xsl:for-each>
914-
}
915-
<xsl:if test="following-sibling::*">,</xsl:if>
916-
</xsl:for-each>
917-
]}
918-
</xsl:template>
919-
</xsl:stylesheet>
920-
EOC;
900+
<?xml version="1.0"?>
901+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
902+
<xsl:output method="text"/>
903+
<xsl:variable name='q'>"</xsl:variable>
904+
905+
<xsl:template match="/recordset">
906+
<xsl:value-of select='concat("{", $q, @zname, $q, ": [")' />
907+
<xsl:for-each select='/*/row'>
908+
{
909+
<xsl:for-each select='field'>
910+
<xsl:value-of select='concat($q, @id, $q)' />: <xsl:value-of select='concat($q, ., $q)' />
911+
<xsl:if test="following-sibling::*">,</xsl:if>
912+
</xsl:for-each>
913+
}
914+
<xsl:if test="following-sibling::*">,</xsl:if>
915+
</xsl:for-each>
916+
]}
917+
</xsl:template>
918+
</xsl:stylesheet>
919+
EOC;
921920
}
922921

923922
public static function saveJsonStylesheet($mode) {

tests/resources/recordset.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<recordset zname="options" zmode="data" count="1">
3+
<row>
4+
<field id="userid"><![CDATA[3]]></field>
5+
<field id="name"><![CDATA[george]]></field>
6+
<field id="option1"><![CDATA[2]]></field>
7+
<field id="option2"><![CDATA[3]]></field>
8+
<field id="option3"><![CDATA[4]]></field>
9+
</row>
10+
</recordset>

0 commit comments

Comments
 (0)