This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: XML -> XML


Jon,

>Anybody have an example of a stylesheet that will take raw xml and keep it
>in the same format, but maybe change an attribute, say:
>
>date="some format"
>
>to
>
>date="some new format"
>
>while not touching anything else?

Sure.  You want to create copies of most nodes.  The 'copy me, but pay
attention to my contents' templates look like:

<xsl:template match="*">
  <xsl:copy>
    <xsl:apply-templates select="@*" />
    <xsl:apply-templates />
  </xsl:copy>
</xsl:template>

<xsl:template match="@*">
  <xsl:copy-of select="." />
</xsl:template>

[Uses the built-in templates to get to the document element and to copy the
value of any text nodes.  I haven't included copying processing
instructions etc. here.]

These templates are very general - they don't give names to match on or use
predicates - so they're given low priority.  Any template that you have
that *does* use a name or a predicate will be applied in preference.  So,
for your exception, do:

<xsl:template match="@date[. = 'some format']">
  <xsl:attribute name="date">some new format</xsl:attribute>
</xsl:template>

This will make any date attribute with a value of 'some format' be changed
into a date attribute with a value of 'some new format'.  If there are any
other restrictions on what the date should be (like what element it's an
attribute on), you can put them in the match pattern as well.

I hope that this helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]