Hallo,
ich habe ein XML Dokument, dass ich nahezu 1:1 per XSLT kopieren möchte, jedoch soll ein Regex-Wert mit einem Wert aus einer anderen XML ausgetauscht werden. Folgendes klappt schonmal ganz gut:
Quell-XML
Hier ist das "source.xml" mit dem einzusetzenden Wert:
Hier das XSL, dass anstelle von %name% den Wert Max Mustermann einsetzt:
Mein Ziel ist es nun die "source.xml" zu erweitern, so dass die XSL-Datei allgemeingültig bleiben kann und aus der Source der zu ersetzende Marker mit seinem neuen Wert stehen kann. Davon evtl. auch mehrere. Dieser Code hier funktioniert nicht, da man bei "template match" keine Variablen angeben kann.
die neue "source.xml":
die veränderte XSL-Datei:
Kann mir jemand sagen, wie ich das Problem umschiffen kann. Ich habe schon ne Weile gesucht und bin schon froh, dass Variante 1 funktioniert. Danke
Gruss
Dom
ich habe ein XML Dokument, dass ich nahezu 1:1 per XSLT kopieren möchte, jedoch soll ein Regex-Wert mit einem Wert aus einer anderen XML ausgetauscht werden. Folgendes klappt schonmal ganz gut:
Quell-XML
HTML Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <idPkg:Story xmlns:idPkg="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" DOMVersion="7.0"> <Story Self="ud9" AppliedTOCStyle="n" TrackChanges="false" StoryTitle="$ID/" AppliedNamedGrid="n"> <StoryPreference OpticalMarginAlignment="false" OpticalMarginSize="12" FrameType="TextFrameType" StoryOrientation="Horizontal" StoryDirection="LeftToRightDirection"/> <InCopyExportOption IncludeGraphicProxies="true" IncludeAllResources="false"/> <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/$ID/NormalParagraphStyle" Justification="CenterAlign"> [...] <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]" FillColor="Color/C=0 M=100 Y=0 K=0" FontStyle="Bold" PointSize="18"> <Properties> <AppliedFont type="string">Times New Roman</AppliedFont> </Properties> <Content>S </Content> </CharacterStyleRange> <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]" FontStyle="Bold" PointSize="18"> <Properties> <AppliedFont type="string">Times New Roman</AppliedFont> </Properties> <Content>%name%</Content> </CharacterStyleRange> </ParagraphStyleRange> </Story> </idPkg:Story>
HTML Code:
<name>Max Mustermann</name>
HTML Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:variable name="insertIn"> <xsl:text>/Users/max/Desktop/switch_test/source.xml</xsl:text> </xsl:variable> <xsl:variable name="insertion"> <xsl:value-of select="document($insertIn)//name"/> </xsl:variable> <xsl:template match="Content[.='%name%']"> <xsl:element name="Content"> <xsl:value-of select="$insertion" /> </xsl:element> </xsl:template> </xsl:stylesheet>
die neue "source.xml":
HTML Code:
<story> <replace regex="%name%">Max Mustermann</replace> </story>
HTML Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:variable name="insertFrom"> <xsl:text>/Users/max/Desktop/switch_test/source.xml</xsl:text> </xsl:variable> <xsl:variable name="replaceThis"> <xsl:value-of select="document($insertFrom)/story/@regex"/> </xsl:variable> <xsl:variable name="insertThis"> <xsl:value-of select="document($insertFrom)/story/replace"/> </xsl:variable> <xsl:template match="Content[.='$replaceThis']"> <xsl:element name="Content"> <xsl:value-of select="$insertThis" /> </xsl:element> </xsl:template> </xsl:stylesheet>
Gruss
Dom
Comment