Forenindex » Programme » Print/Bildbearbeitung » Adobe InDesign » XML, XLST Teil eines Strings am Ende eines Node-Inhalts entfernen

XML, XLST Teil eines Strings am Ende eines Node-Inhalts entfernen

fruitsalad
Beiträge gesamt: 16

24. Jul 2014, 15:25
Bewertung:

gelesen: 1853

Beitrag als Lesezeichen
Hallo,

wir erstellen gerade einen Katalog mit Indesign und XML Import. Mittels XLST ändern wir die XML aus OpenOffice, damit diese in Indeisgn importiert werden kann.

Nun würden wir gerne bei unseren Artikelnummern, in bestimmten Fällen, Teile am Ende entfernen.

Ein Beispiel ist:

53-10035-54 soll zu 53-10035 umgeformt werden.

Allgemein sollen bei allen Artikelnummer, die ein "-" gefolgt von zwei Ziffern aufweisen, diese am Ende entfernt werden.

Ein anderes Forenmitglied, sagte uns bereits, das wir diese Fälle mit einer RegEx
Code
-\d{2}\> 

finden könnten.

Mit der Funktion replace lassen sich dann diese Fälle wohl umformen. Allerdings wissen wir nicht, wie wir dies in unserer XLST einbauen, so dass die Suche auf alle Artikelnummern angewandt wird und die Artikelnummern geändert werden.

Ein Auszug unserer XML wäre folgender:

Code
<?xml version="1.0" encoding="UTF-8" ?> 
<ooo_calc_export scriptVersion="2.2.0" scriptUpdate="2010-12-19" scriptURL="http://www.digitalimprint.com/misc/oooexport/" scriptAuthor="vjl">
<ooo_sheet num="1" name="Tabelle1">
<ooo_row>
<Artikelnr>2-13629-54</Artikelnr>
<ooo_col_2></ooo_col_2>
<ooo_col_3>Katalog / 2015 / Solitär / 01</ooo_col_3>
<Details>Ring 18 kt RG + WG, 1 Brill. 0,20 ct, TW-si</Details>
<Bestell>ILR3209A</Bestell>
<GH-vorl_ufig>489</GH-vorl_ufig>
<GH></GH>
<Rabatt></Rabatt>
<Haendler></Haendler>
<Faktor></Faktor>
<Publikum></Publikum>
<Zus_tzliche_Info>6er Krappe</Zus_tzliche_Info>
<Bildlink>CMYK/2-13629-54_2-13630</Bildlink>
<Link></Link>
<Frei_A></Frei_A>
<Frei_B></Frei_B>
<Frei_C></Frei_C>
<Frei_D></Frei_D>
</ooo_row>
<ooo_row>
<Artikelnr>2-13630</Artikelnr>
<ooo_col_2></ooo_col_2>
<ooo_col_3>Katalog / 2015 / Solitär / 01</ooo_col_3>
<Details>Ring 18 kt RG + WG, 1 Brill. 0,25 ct, TW-si</Details>
<Bestell>ILR3209B</Bestell>
<GH-vorl_ufig>569</GH-vorl_ufig>
<GH></GH>
<Rabatt></Rabatt>
<Haendler></Haendler>
<Faktor></Faktor>
<Publikum></Publikum>
<Zus_tzliche_Info>7er Krappe</Zus_tzliche_Info>
<Bildlink>CMYK/2-13629-54_2-13630</Bildlink>
<Link></Link>
<Frei_A></Frei_A>
<Frei_B></Frei_B>
<Frei_C></Frei_C>
<Frei_D></Frei_D>
</ooo_row>
</ooo_sheet>
</ooo_calc_export>



Unsere XLST ist folgende:

Code
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0"/>
<xsl:output method = "xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="ooo_sheet">
<Root>
<xsl:for-each select="ooo_row">
<Artikel>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Artikelnummer</xsl:attribute>
<xsl:value-of select="Artikelnr"/>
</Artikelnummer>
<Bild>
<xsl:attribute name="href">
<xsl:text>file:///</xsl:text>
<xsl:value-of select="Bildlink"/>
<xsl:text>.PSD</xsl:text>
</xsl:attribute>
</Bild>
<Text>
<EK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">EK</xsl:attribute>
<xsl:text> </xsl:text>
<xsl:value-of select="Haendler"/>
<xsl:text>,- </xsl:text>
</EK>
<VK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">VK</xsl:attribute>
<xsl:text> </xsl:text>
<xsl:value-of select="Publikum"/>
<xsl:text>,- </xsl:text>
</VK>
<Details xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Details</xsl:attribute>
<xsl:value-of select="Details"/>
<xsl:text>, </xsl:text>
</Details>




<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Artikelnummer</xsl:attribute>
<xsl:value-of select="Artikelnr"/></Artikelnummer>





<Link xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Link</xsl:attribute>
<xsl:value-of select="Link"/>
</Link>
<Frei_A xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_A</xsl:attribute>
<xsl:value-of select="Frei_A"/>
</Frei_A>
<Frei_B xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_B</xsl:attribute>
<xsl:value-of select="Frei_B"/>
</Frei_B>
<Frei_C xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_C</xsl:attribute>
<xsl:value-of select="Frei_C"/>
</Frei_C>
<Frei_D xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_D</xsl:attribute>
<xsl:value-of select="Frei_D"/>
</Frei_D>
</Text>
</Artikel>
</xsl:for-each>
</Root>
</xsl:template>
</xsl:stylesheet>


Der abgesetzte Bereich ist der Teil, in dem wir die Artikelnummer aus dem XML übernehmen.

Wäre super wenn uns jemand von Euch helfen könnte.

Vielen Dank im Voraus

(Dieser Beitrag wurde von fruitsalad am 24. Jul 2014, 15:39 geändert)

XML, XLST Teil eines Strings am Ende eines Node-Inhalts entfernen

zaphodbeeblebroxx
Beiträge gesamt: 408

24. Jul 2014, 22:52
Bewertung:

gelesen: 1795

Beitrag als Lesezeichen
Hallo fruitsalad,

wenn immer am Ende von "Artikeln" die 2 Ziffern nach einem Divis entfernt werden sollen, dann so:
Code
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">  
<xsl:attribute name="aid5:cstyle">Artikelnummer</xsl:attribute>
<xsl:value-of select="replace(Artikelnr/text(),'-\d\d$','')"/></Artikelnummer>



Matthias

XML, XLST Teil eines Strings am Ende eines Node-Inhalts entfernen

fruitsalad
Beiträge gesamt: 16

25. Jul 2014, 10:27
Bewertung:

gelesen: 1754

Beitrag als Lesezeichen
Hallo,

danke für deine Antwort,

ich habe deinen Code in unser XSLT eingebaut. Irgendwie werden jetzt nach der Transformation überhaupt keine Artikelnummern mehr angezeigt.

Unser Test-XML war:

Code
<?xml version="1.0" encoding="UTF-8" ?> 
<ooo_calc_export scriptVersion="2.2.0" scriptUpdate="2010-12-19" scriptURL="http://www.digitalimprint.com/misc/oooexport/" scriptAuthor="vjl">
<ooo_sheet num="1" name="Tabelle1">
<ooo_row>
<Artikelnr>C71-12451</Artikelnr>
<ooo_col_2></ooo_col_2>
<ooo_col_3>Katalog / 2015 / Leerfassungen / 1 ct Mittelstein / 01</ooo_col_3>
<Details>Ring 18 kt WG, 2 Tropfen 0,38 ct, TW-si, für 1,00 ct</Details>
<Bestell>M01475R</Bestell>
<GH-vorl_ufig>1109</GH-vorl_ufig>
<GH></GH>
<Rabatt></Rabatt>
<Haendler></Haendler>
<Faktor></Faktor>
<Publikum></Publikum>
<Bildlink>CMYK/C71-12451</Bildlink>
<Link></Link>
<Frei_A></Frei_A>
<Frei_B></Frei_B>
<Frei_C></Frei_C>
<Frei_D></Frei_D>
</ooo_row>
<ooo_row>
<Artikelnr>2-13537-54</Artikelnr>
<ooo_col_2></ooo_col_2>
<ooo_col_3>Katalog / 2015 / Leerfassungen / 1 ct Mittelstein / 01</ooo_col_3>
<Details>Ring "4er-Krappe" 18 kt WG, für 1,00 ct</Details>
<Bestell>ILR3213C</Bestell>
<GH-vorl_ufig>289</GH-vorl_ufig>
<GH></GH>
<Rabatt></Rabatt>
<Haendler></Haendler>
<Faktor></Faktor>
<Publikum></Publikum>
<Bildlink>CMYK/2-13537-54</Bildlink>
<Link></Link>
<Frei_A></Frei_A>
<Frei_B></Frei_B>
<Frei_C></Frei_C>
<Frei_D></Frei_D>
</ooo_row>
</ooo_sheet>
</ooo_calc_export>


Das XSLT:

Code
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="ooo_sheet">
<Beschreibung_1>
<xsl:for-each select="ooo_row">
<Artikel>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Artikelnummer</xsl:attribute>
<xsl:value-of select="Artikelnr" />
</Artikelnummer>
<Bild>
<xsl:attribute name="href">
<xsl:text>file:///</xsl:text>
<xsl:value-of select="Bildlink" />
<xsl:text>.PSD</xsl:text>
</xsl:attribute>
</Bild>
<Text>
<EK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">EK</xsl:attribute>
<xsl:text></xsl:text>
<xsl:value-of select="Haendler" />
<xsl:text>,-</xsl:text>
</EK>
<VK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">VK</xsl:attribute>
<xsl:text></xsl:text>
<xsl:value-of select="Publikum" />
<xsl:text>,-</xsl:text>
</VK>
<Details xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Details</xsl:attribute>
<xsl:value-of select="Details" />
<xsl:text>,</xsl:text>
<xsl:text>&#xa;</xsl:text>
</Details>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Artikelnummer</xsl:attribute>
<xsl:value-of select="replace(Arikelnr/text(),'-\d\d$','')" />
</Artikelnummer>
<Link xmlns:aid="http://ns.adobe.comt/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Link</xsl:attribute>
<xsl:value-of select="Link" />
</Link>
<Frei_A xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_A</xsl:attribute>
<xsl:value-of select="Frei_A" />
</Frei_A>
<Frei_B xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_B</xsl:attribute>
<xsl:value-of select="Frei_B" />
</Frei_B>
<Frei_C xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_C</xsl:attribute>
<xsl:value-of select="Frei_C" />
</Frei_C>
<Frei_D xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<xsl:attribute name="aid5:cstyle">Frei_D</xsl:attribute>
<xsl:value-of select="Frei_D" />
</Frei_D>
</Text>
</Artikel>
</xsl:for-each>
</Beschreibung_1>
</xsl:template>
</xsl:stylesheet>


Heraus kam dann folgendes:

Code
<?xml version="1.0" encoding="UTF-8" ?> 
<Beschreibung_1>
<Artikel>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Artikelnummer">C71-12451</Artikelnummer>
<Bild href="file:///CMYK/C71-12451.PSD" />
<Text>
<EK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="EK">,-</EK>
<VK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="VK">,-</VK>
<Details xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Details">Ring 18 kt WG, 2 Tropfen 0,38 ct, TW-si, f&#65533;&#65533;r 1,00 ct,
</Details>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Artikelnummer" />
<Link xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" xmlns:aid="http://ns.adobe.comt/AdobeInDesign/4.0/" aid5:cstyle="Link" />
<Frei_A xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_A" />
<Frei_B xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_B" />
<Frei_C xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_C" />
<Frei_D xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_D" />
</Text>
</Artikel>
<Artikel>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Artikelnummer">2-13537-54</Artikelnummer>
<Bild href="file:///CMYK/2-13537-54.PSD" />
<Text>
<EK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="EK">,-</EK>
<VK xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="VK">,-</VK>
<Details xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Details">Ring "4er-Krappe" 18 kt WG, f&#65533;&#65533;r 1,00 ct,
</Details>
<Artikelnummer xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Artikelnummer" />
<Link xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" xmlns:aid="http://ns.adobe.comt/AdobeInDesign/4.0/" aid5:cstyle="Link" />
<Frei_A xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_A" />
<Frei_B xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_B" />
<Frei_C xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_C" />
<Frei_D xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:cstyle="Frei_D" />
</Text>
</Artikel>
</Beschreibung_1>

XML, XLST Teil eines Strings am Ende eines Node-Inhalts entfernen

fruitsalad
Beiträge gesamt: 16

25. Jul 2014, 11:26
Bewertung:

gelesen: 1734

Beitrag als Lesezeichen
Hallo,

ich muss mich selbst korrigieren. Irgendwie scheine ich es doch tatsächlich geschafft zu haben in diese eine Zeile einen Fehler einzubauen...

Der Code funktioniert nun!

Vielen Dank!