chrisen
Goto Top

XSLT v2 in XSLT v1

Hallo zusammen,
ich habe ein Problem mit der Konvertierung vom XML Dateien via XSLT. Version 2 und Version 1.

Und zwar ist es durch meinen Hoster nicht möglich mittels eines PHP Skripts ein XSLT version 2 Dokument zu Transformieren.
Diese Skript funktioniert nur mit XSLT v1:
#!/usr/local/php5.6/bin/php

<?php
$xml = new DOMDocument;
$xml->load('//Import/Rohdatei/product.xml');  

$xsl = new DOMDocument;
$xsl->load('//Import/XSLT/Articles.xslt');  

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);

$newDOM = $proc->transformToDoc($xml);
$newDOM->formatOutput = true;
$newDOM->save("//Ort/Artikel.xml")  
?>

Wie kann ich diesen Teil der XSLT v2 in XSLT v1 umsetzen? Bzw. geht das Überhaupt?

<xsl:for-each-group select="*[starts-with(local-name(),'property')]" group-starting-with="*[starts-with(local-name(),'propertyGroupName')]">  
	<propertyValue>
		<propertyGroupName><xsl:value-of select="current-group()[1]" /></propertyGroupName>  
		<propertyOptionName><xsl:value-of select="current-group()[2]" /></propertyOptionName>  
		<propertyValueName><xsl:value-of select="current-group()[3]" /></propertyValueName>  
	</propertyValue>
</xsl:for-each-group>

Ausgangs XML ist diese:

 <propertyGroupName3>1A</propertyGroupName3>
 <propertyOptionName3>2A</propertyOptionName3>
 <propertyValueName3>3A</propertyValueName3>
 <propertyGroupName4>1B</propertyGroupName4>
 <propertyOptionName4>2B</propertyOptionName4>
 <propertyValueName4>3B</propertyValueName4>
 <propertyGroupName5>1C</propertyGroupName5>
 <propertyOptionName5>2C</propertyOptionName5>
 <propertyValueName5>3C</propertyValueName5>
 <propertyGroupName7>1D</propertyGroupName7>
 <propertyOptionName7>2D</propertyOptionName7>
 <propertyValueName7>3D</propertyValueName7>

Raus kommen soll diese Struktur:

<propertyValue>
	<propertyGroupName>1A</propertyGroupName>
	<propertyOptionName>2A</propertyOptionName>
	<propertyValueName>3A</propertyValueName>
</propertyValue>
<propertyValue>
	<propertyGroupName>1B</propertyGroupName>
	<propertyOptionName>2B</propertyOptionName>
	<propertyValueName>3B</propertyValueName>
</propertyValue>
<propertyValue>
	<propertyGroupName>1C</propertyGroupName>
	<propertyOptionName>2C</propertyOptionName>
	<propertyValueName>3C</propertyValueName>
</propertyValue>
<propertyValue>
	<propertyGroupName>1D</propertyGroupName>
	<propertyOptionName>2D</propertyOptionName>
	<propertyValueName>3D</propertyValueName>
</propertyValue>

Würde mich riesig über eure Antworten freuen!

Grüße,
chrisen

Content-Key: 315344

Url: https://administrator.de/contentid/315344

Ausgedruckt am: 28.03.2024 um 13:03 Uhr

Mitglied: colinardo
Lösung colinardo 15.09.2016 aktualisiert um 15:28:01 Uhr
Goto Top
Hallo @chrisen,
kannst du mit folgendem "xsl for-each" Schnippsel machen (in dein bestehendes XSLT einbauen), das ist XSLT v1 kompatibel und macht das gleiche wie das XLST v2 von oben:
<xsl:for-each select="*[starts-with(local-name(),'propertyGroupName')]">  
      <xsl:variable name="pos" select="position()" />   
	 <propertyValue>
            <propertyGroupName><xsl:value-of select="."/></propertyGroupName>  
	    <propertyValueName><xsl:value-of select="../*[starts-with(local-name(),'propertyOptionName')][$pos]"/></propertyValueName>  
            <propertyOptionName><xsl:value-of select="../*[starts-with(local-name(),'propertyValueName')][$pos]"/></propertyOptionName>  
        </propertyValue>
</xsl:for-each>
Würde mich riesig über eure Antworten freuen!
Ich mich auch ab und zu über ein kühles Bierchen face-smile

Grüße Uwe
Mitglied: chrisen
chrisen 15.09.2016 um 16:01:40 Uhr
Goto Top
Super vielen Dank!!

Ich mich auch ab und zu über ein kühles Bierchen face-smile

Kühles Bierchen ist unterwegs ;)
Mitglied: colinardo
colinardo 15.09.2016 um 17:07:23 Uhr
Goto Top
Zitat von @chrisen:
Kühles Bierchen ist unterwegs ;)
Zischhhhhhh, Merci face-smile!!